python get an address by latitude and longitude Detailed Baidu Maps API

This article is mainly to introduce the relevant information on python obtain the latitude and longitude to an address by Baidu Maps API, the paper sample code described in great detail, has a certain reference value of learning for all of us to learn or work, we need friends below with the small series together to learn learn it.
Foreword

These days more free, came in contact with the next Baidu Maps API (Developer Center link address: http: //developer.baidu.com), found that calling is very convenient, this article will give you a detailed introduction to python by Baidu Maps API access to relevant content latitude and longitude of an address to share learning for your reference, the following did not talk much to say, to take a look at the detailed introduction.

Apply for Baidu API

1, open the page http://lbsyun.baidu.com/index.php?title= Home

Select the service map, click on the left of acquisition key, and then follow the requirements can apply for, you need to Baidu mobile phones and email accounts and certification. Here Insert Picture Description
Here Insert Picture Description
After activation can see the background page, you can now start creating the application, and where the check request in two ways, one is the white list IP, the other is the SN check (next to these calculations), I chose the school SN test: Here Insert Picture Description
after successfully get their AK and SK, followed by instructions on how to calculate sn

Calculating SN (python3.x)

from urllib import parse
import hashlib 
def get_urt(addtress): 
 # 以get请求为例http://api.map.baidu.com/geocoder/v2/?address=百度大厦&output=json&ak=你的ak
 queryStr = '/geocoder/v2/?address=%s&output=json&ak=你的ak' % addtress 
 # 对queryStr进行转码,safe内的保留字符不转换
 encodedStr = parse.quote(queryStr, safe="/:=&?#+!$,;'@()*[]") 
 # 在最后直接追加上yoursk
 rawStr = encodedStr + '你的sk'
 #计算sn
 sn = (hashlib.md5(parse.quote_plus(rawStr).encode("utf8")).hexdigest())  
 #由于URL里面含有中文,所以需要用parse.quote进行处理,然后返回最终可调用的url
 url = parse.quote("http://api.map.baidu.com"+queryStr+"&sn="+sn, safe="/:=&?#+!$,;'@()*[]")  
 return url

The url can be directly accessed, returns json format, as follows

{"status":0,"result":{"location":{"lng":116.50104690641698,"lat":39.79092147361288},"precise":1,"confidence":80,"level":"地产小区"}}

to sum up

That's all for this article, I hope the contents of this paper has some reference value of learning for everyone to learn or work
the last to recommend a very wide python learning resource gathering, [click to enter] , where I gather there before learning experience, learning pen

Remember, there is a glimmer of corporate experience, and calmed down to zero on the basis of the actual project data, we can also below the message, not the

Understand proposed, we will study together progress

Published 57 original articles · won praise 25 · views 70000 +

Guess you like

Origin blog.csdn.net/haoxun11/article/details/105129159