Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https: //blog.csdn.net/weixin_39626452/article/details/91346446
Geocoding positive and negative decoding
Positive geocoding: Convert the coordinates address details;
reverse geocoding: DETAILED addresses into coordinates;
Baidu Maps API
URL: http: //lbsyun.baidu.com/index.php title = webapi / guide / webservice-geocoding-abroad?
Use:
Create a new application to obtain ak:
quota:
Apply for individual developers can be, need to fill out some personal information, will be able to fill in after the entry into force immediately, it can process one day's 300,000 data the
invocation:
http://api.map.baidu.com/geocoder/v2/?callback=renderReverse&location=35.658651,139.745415&output=json&pois=1&latest_admin=1&ak=您的ak //GET请求
High German Maps API
High moral map of API usage and Baidu similar, but also need to apply for an account and create a new application to obtain key, high moral map information obtained reverse geocoding richer than Baidu map, such as road numbers around, these are not Baidu map.
URL: https: //lbs.amap.com/api/webservice/guide/api/georegeo
invocation:
https://restapi.amap.com/v3/geocode/regeo?output=json&location=116.310003,39.991957&key=<用户的key>&radius=1000&extensions=all
Please refer to the specific use of Net document examiner.
quota:
High German quota really very small, very unfriendly for individual developers, and apply a lot of trouble, you can only buy (too expensive)
Python implementation reverse geocoding
import requests
#我这里是将经纬度转换为地址,所以选用的是逆地理编码的接口。
#https://restapi.amap.com/v3/geocode/regeo?
#output=xml&location=116.310003,39.991957&key=<用户的key>&radius=1000&extensions=all
#高德地图
def geocode1(location):
parameters = {'output': 'json', 'location': location, 'key': 'b65ac7bac54ed07220e8d05ab93ad469','extensions':'all'}
base = 'https://restapi.amap.com/v3/geocode/regeo'
response = requests.get(base, parameters)
answer = response.json()
print('url:' + response.url)
print(answer)
return answer['regeocode']['formatted_address'],answer['regeocode']['roads'][0]['id'],answer['regeocode']['roads'][0]['name']
#百度地图
def geocode(location):
parameters = {'location': location, 'output': 'json', 'coordtype': 'gcj02ll', 'pois': '0', 'latest_admin': '1', 'ak': 'FUu6OTikvprEEwd1qL9X23a9PGq05efW','extensions_road':'true'}
base = 'http://api.map.baidu.com/geocoder/v2/'
response = requests.get(base, parameters)
#response=requests.get('http://api.map.baidu.com/geocoder/v2/?location=30.48686,104.07649&output=json&pois=1&latest_admin=1&ak=U1ck8zXZpoWGYqv2ozr8Xa3IraDfy4Vw')
print('url:' + response.url)
answer = response.json()
print(answer)
return answer['result']['formatted_address'],answer['result']['addressComponent']['adcode'],answer['result']['addressComponent']['street']
xtmp = 104.07649
ytmp = 30.48686
locations=str(ytmp)+','+str(xtmp)
detail,id,name = geocode(locations)
print(detail)
print(id)
print(name)
Back to Results
I mainly want to get the coordinates of where the road information is
Baidu : {
'Status': 0,' the Result ': {' LOCATION ': {' lng ': 104.08302723175203,' LAT ': 30.492757831966063},
' formatted_address': 'Sichuan Province Road Chengdu, some double Foothills area ',' business': '' , 'addressComponent': { 'country': ' Chinese', 'COUNTRY_CODE': 0, 'country_code_iso': 'CHN',
'country_code_iso2': 'the CN' , 'province': 'Sichuan', 'city': 'Chengdu', 'city_level': 2, 'district': ' double region', 'Town': '', 'adcode': '510 116',
' street ':' Foothills Avenue period ',' street_number ':' ' ,' direction ':' ',' distance ':' '},' pois ': [],' roads ': [{' name ':' Foothills Avenue for some ',' distance ':' 4 '}],' poiRegions': [], 'sematic_description': ' Earl Hill Palace Ting Shanjing Nordic northwest 55 m villa', 'cityCode': 75} }
Sichuan Province, Chengdu Shuangliu Foothills Boulevard area for some
510,116
Foothills Boulevard period
High De : { 'status':' 1 ',' regeocode ': {' roads': [{ 'id': '028H48F0190173801', 'location': '104.076,30.4869', 'direction': ' East', ' name ':' Foothills Avenue period ',' distance ': '16 .5556 '}, { 'id': '028H48F0190173007', 'location': '104.079,30.4866', 'direction': ' West', 'name': ' Azusa Avenue South for a state ',' distance ':' 204.268 '}, {' id ':' 028H48F0200171789 ',' location ':' 104.08,30.4865 ',' direction ':' West ',' name ':' Red Road South extension period ',' distance ':' 372.873 '}],' roadinters ': [{' second_name ':' Foothills Avenue period ',' first_id ':' 028H48F0190173007 ',' second_id ':' 028H48F0190173801 ',' location ':' 104.0785992,30.48659389 ',' distance ':' 204.268 ',' first_name ':' Azusa Avenue South for a state ',' direction ':' West '}],' formatted_address ': ' Shuangliu District, Chengdu, Sichuan, China Town street Foothills Fragrant Peninsula Road period ',' addressComponent ': {' city ':' Chengdu ',' province ':' Sichuan ', ... (hereinafter omitted)
Sichuan Shuangliu region Huayang street Avenue Foothills period of Xiangshan Peninsula
028H48F0190173801
Foothills Boulevard period