Python-based Map coordinate service interface Call code instance

Source: Internet
Author: User
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 ()
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.