Fork me on GitHub

基于python的WGS84转百度坐标

from urllib.request import urlopen, quote
import json
def wgs84tobaidu(x,y):
    data=str(x)+','+str(y);
    output = 'json'
    url='http://api.map.baidu.com/geoconv/v1/?coords='+data+'&from=1&to=5&output=' +output+'&ak=百度地图密钥'
    req = urlopen(url)
    res = req.read().decode() 
    temp = json.loads(res)
    baidu_x=0
    baidu_y=0
    if temp['status']==0:
        baidu_x=temp['result'][0]['x']
        baidu_y=temp['result'][0]['y']
     
    return baidu_x,baidu_y

 

posted @ 2018-11-17 22:19  壶小旭  阅读(1913)  评论(1编辑  收藏  举报