通过Google map api 来查询某个地址的经纬度
#Python 源代码
#查询大理三塔的经纬度
import urllib
import urllib2
import json
params = {'address': 'three pagodas,Dali,Yunnan,China','sensor': 'false'}
url = 'http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode(params)
rawreply = urllib2.urlopen(url).read()
result = json.loads(rawreply)
print json.dumps([(s['formatted_address'],s['geometry']) for s in result['results'], indent=2)
#源代码结束
下面是运行结果
[
[
"The Chongsheng Temple and the Three-Pagoda \uff08Northwest Gate\uff09, 214 National Road, Dali, Yunnan, China, 671003",
{
"location": {
"lat": 25.7060618,
"lng": 100.1493156
},
"viewport": {
"northeast": {
"lat": 25.7074107802915,
"lng": 100.1506645802915
},
"southwest": {
"lat": 25.7047128197085,
"lng": 100.1479666197085
}
},
"location_type": "APPROXIMATE"
}
]
]
#查询大理三塔的经纬度
import urllib
import urllib2
import json
params = {'address': 'three pagodas,Dali,Yunnan,China','sensor': 'false'}
url = 'http://maps.googleapis.com/maps/api/geocode/json?' + urllib.urlencode(params)
rawreply = urllib2.urlopen(url).read()
result = json.loads(rawreply)
print json.dumps([(s['formatted_address'],s['geometry']) for s in result['results'], indent=2)
#源代码结束
下面是运行结果
[
[
"The Chongsheng Temple and the Three-Pagoda \uff08Northwest Gate\uff09, 214 National Road, Dali, Yunnan, China, 671003",
{
"location": {
"lat": 25.7060618,
"lng": 100.1493156
},
"viewport": {
"northeast": {
"lat": 25.7074107802915,
"lng": 100.1506645802915
},
"southwest": {
"lat": 25.7047128197085,
"lng": 100.1479666197085
}
},
"location_type": "APPROXIMATE"
}
]
]
![]() |
还没人赞这篇日记