Python-based map coordinate service interface call code example code description: Python-based map coordinate service interface call code example
Associated Data: map coordinate service
#! /Usr/bin/python #-*-coding: UTF-8-*-import json, urllibfrom urllib import urlencode # ------------------------------ # -------------------------------- def main (): # configure the APPKey appkey = "************************" #1. longitude and latitude conversion request1 (appkey, "GET") # latitude and longitude conversion def request1 (appkey, m = "GET"): url = "http://v.juhe.cn/offset/index" params = {"lng ":"", # longitude, such as: 116.3974965092 "lat": "", # latitude, such as: 39.908700982285396 "type": "", # Conversion type, 1: GPS-> Baidu, 2: baidu-> GPS, 3: GPS-> Google, 4: Google-> GPS
5: Baidu-> Google, 6: Google-> Baidu "dtype": "", # Format of returned data: json, xml, or jsonp. default value: json "callback ":"", # When jsonp is returned, "key": appkey, # The key you applied for} params = urlencode (params) if m = "GET": f = urllib must be passed. urlopen ("% s? % S "% (url, 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: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print "request api error" if _ name _ = '_ main _': main ()