Three methods for obtaining the longitude and latitude by address; three methods for obtaining the province and city by latitude and longitude
# Coding /? Address = % s' % address + '& output = json & ak = Key' html = urllib2.urlopen (url) json1 = html. read () # convert to str type hjson1 = json. loads (json1) # convert to dict type lng1 = hjson1 ['result'] ['location'] ['lng '] # longitude lat1 = hjson1 ['result'] ['location'] [' lat'] # latitude print 'Method 1: ', lng1, lat1 # method 2 http://blog.csdn.net/mrlevo520/article/details/52556625import requestsbase = 'HTTP: // api.map.baidu.com/geocoder/v2 /? Address = startup Research and Development Park, No. 69 jinye Road, Xi'an Hi-Tech Zone & output = json & ak = Key 'response = requests. get (base) answer = response. json () lng = answer ['result'] ['location'] ['lng '] lat = answer ['result'] ['location'] ['lat'] print' method 2: ', lng, lat # reverse query baseop = 'HTTP: // api.map.baidu.com/geocoder/v2 /? Ak = Key & location = 39.911013, 116.413554 & output = json 'responseop = requests. get (baseop) answerop = responseop. json () province = answerop ['result'] ['sssscomponent '] ['province'] city = answerop ['result'] ['sssscomponent '] ['city'] print' method 2 reverse lookup: ', province, city # method 3 http://blog.csdn.net/spacecraft/article/details/43309447from geopy. geocoders import baiduapikey = 'key' # apply for http://lbsyun.baidu.com/apiconsol from the website E/key? Application = keyb = baidu. baidu (apikey) location = B. geocode ("chuangye R & D Park, No. 69 jinye Road, Xi'an Hi-Tech Zone") print 'method 3: ', location. longpolling, location. latitude
# Reverse Lookup
Aa = B. reverse ("22.546834, 113.946787 ")
Ad = aa. address
P_start = ad. index ('province ')
P_end = ad. index ('city ')
Print 'method 3 lookup: ', ad [: p_start + 3], ad [p_start + 3: p_end + 3]