API Address: http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding
A simple API that can be used to obtain latitude and longitude by address (place name), or to obtain the location information of the perimeter via latitude.
AK is Baidu developer Apikey, registered address: http://developer.baidu.com/
#!/usr/bin/env Python3ImportRequestsImportJSONdefLOCATEBYADDR (Address, city=None):" "The city is optional, depending on the address to determine the latitude and longitude" "Items= {'Output':'JSON','AK':'a9f77xxxxxxxxxxxxxxxxxxxxxxxxxx','Address': Address}ifcity:items[' City'] =City R= Requests.get ('http://api.map.baidu.com/geocoder/v2/', params=items) Dictresult=json.loads (R.text)returndictresult['result'][' Location']if notdictresult['Status']ElseNonedefLocatebylatlon (lat, lon, pois=0):" "determine the address based on latitude and longitude" "Items= {' Location': str (LAT) +','+ STR (LON),'AK':'a9f77xxxxxxxxxxxxxxxxxxxxxxxxxx','Output':'JSON'} ifpois:items['POIs'] = 1R= Requests.get ('http://api.map.baidu.com/geocoder/v2/', params=items) Dictresult=json.loads (R.text)returndictresult['result']if notdictresult['Status']ElseNonedefMain (): Address= Input ('Enter Address:') City= Input ('Enter City: (optional)') Result=locatebyaddr (address, city)Print(Result)if __name__=='__main__': Main ()
Run:
Python gets the latitude and longitude of the address via the Baidu Map API