Code Description: Python-based map coordinate service interface Call code instance
Associated data: Map coordinate services
#!/usr/bin/python#-*-coding:utf-8-*-import json, urllibfrom urllib import UrlEncode #------------------------------- ---#----------------------------------def main (): #配置您申请的APPKey Appkey = "*********************" #1. Latitude and longitude conversion Request1 (Appkey, "get") #经纬度转换def Request1 (Appkey, m= "get"): url = "Http://v.juhe.cn/offset/index" params = { "LNG": ", #经度, such as: 116.3974965092" lat ":", #纬度, such as: 39.908700982285396 "type": "", #转换类型,1:gps-> Baidu , 2: Baidu->gps,3:gps-> Google, 4: Google->gps
5: Baidu---Google, 6: google--Baidu "Dtype": ", #返回数据格式: JSON or XML or JSONP, the default JSON" callback ":" ", #返回格式选择jsonp时, must pass "Key": Appkey, #你申请的key} params = UrlEncode (params) if m = = "GET": F = Urllib.urlopen ("%s?%s"% (Ur L, params)) Else:f = Urllib.urlopen (URL, params) content = F.read () res = json.loads (content) If res : Error_code = res["Error_code"] if Error_code = = 0: #成功请求 print res["result"] Else:print "%s:%s"% (res["error_code"],res["Reason"]) else:print "Request API Error" if __nam e__ = = ' __main__ ': Main ()