资源简介
Python,通过Googlemap API获取地点信息,输入地点位置,输出该地点位置详细信息,包括经纬度等。

代码片段和文件信息
# -*- coding: cp936 -*-
# Filename:get Location from googleMap
# Input:address
# Output:lat & lng
# function:
import urllib2
import json
class GoogleMap(object):
def __init__(self location postal):
#将地点以及邮政编码传入,如果没有邮政编码 则传入-1
self.address = location #地址
#组合成的googleapi地址 获取json数据
self.url = ‘http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false‘%self.address
print self.url
self.postalcode = postal #邮编
self.lat = 0.0 #纬度
self.lng = 0.0 #经度
def getPage(self):
#得到页面获取数据
self.url=self.url.encode(‘utf-8‘)
self.url=urllib2.unquote(self.url)
response = urllib2.urlopen(self.url)
jsonGeocode = response.read()
jsonVal = json.loads(jsonGeocode)
HaveResult = False #标志变量
#判断是否获取成功
if(jsonVal[‘status‘] != ‘OK‘):
return False
else:
for result in jsonVal[‘results‘]:
#print result[‘address_components‘]
for val in result[‘address_components‘]:
if(val[‘types‘][0] == ‘postal_code‘):
#得到邮政编码 进行比对矫正
if(self.postalcode != “-1“ and val[‘long_name‘] != self.postalcode):
continue
print “postal code:“ + str(val[‘long_name‘])
self.lat = result[‘geometry‘][‘location‘][‘lat‘]
self.lng = result[‘geometry‘][‘location‘][‘lng‘]
print “address:“ + result[‘formatted_address‘].encode(‘utf-8‘)
print “lat:“ + str(self.lat)
print “lng:“ + str(self.lng)
print “\n“
return True
def main():
address= “北京天安门“
newMap = GoogleMap(address.decode(“gbk“) “-1“)
newMap.getPage()
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 37 2017-11-05 13:52 说明.txt
文件 2073 2017-11-05 13:47 googleMap.py
相关资源
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
- 量化交易(附python常见函数的使用方
- python 名字用字排行
评论
共有 条评论