Home > Backend Development > Python Tutorial > Python-based map coordinate service interface calling code example

Python-based map coordinate service interface calling code example

大家讲道理
Release: 2016-11-09 10:42:28
Original
1297 people have browsed it

Code description: Python-based map coordinate service interface calling code example

Associated data: map coordinate service

#!/usr/bin/python
# -*- coding: utf-8 -*-
import json, urllib
from 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->谷歌, 4:谷歌->GPS<br/>     5:百度->谷歌 ,6:谷歌->百度
        "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__ == &#39;__main__&#39;:
    main()
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template