1. 程式人生 > >基於python的WGS84轉百度座標

基於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