Python-based map coordinate service interface call code instance

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

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.