基於Python的地圖座標服務介面調用代碼執行個體

來源:互聯網
上載者:User
代碼描述:基於Python的地圖座標服務介面調用代碼執行個體

關聯資料:地圖座標服務

#!/usr/bin/python# -*- coding: utf-8 -*-import json, urllibfrom urllib import urlencode  #----------------------------------#----------------------------------  def main():      #配置您申請的APPKey    appkey = "*********************"      #1.經緯度轉換    request1(appkey,"GET")      #經緯度轉換def request1(appkey, m="GET"):    url = "http://v.juhe.cn/offset/index"    params = {        "lng" : "", #經度,如:116.3974965092        "lat" : "", #緯度,如:39.908700982285396        "type" : "", #轉換類型,1:GPS->百度, 2: 百度->GPS ,3:GPS->Google, 4:Google->GPS
5:百度->Google ,6:Google->百度 "dtype" : "", #返回資料格式:json或xml或jsonp,預設json "callback" : "", #返回格式選擇jsonp時,必須傳遞 "key" : appkey, #你申請的key } params = urlencode(params) if m =="GET": f = urllib.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: #成功請求 print res["result"] else: print "%s:%s" % (res["error_code"],res["reason"]) else: print "request api error" if __name__ == '__main__': main()
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.