Python查詢一個城市的Google地圖的經度和緯度

來源:互聯網
上載者:User

標籤:python


Python查詢一個城市的Google地圖的經度和緯度
設定Python環境

shou#!/usr/bin/env  python


編寫指令碼

import argparse
import os
import urllib
import requests
ERROR_STRING = ‘’

def find_lat_long(city):
“”” Find geographic coordinates “””
# Encode query string into Google maps URL
#url = ‘https://www.google.com/maps/place/’ + urllib.quote(city)
response = requests.get(‘https://maps.googleapis.com/maps/api/geocode/json?address=’ + urllib.quote(city))
resp_json_payload = response.json()
# Get XML location from Google maps
print(resp_json_payload[‘results’][0][‘geometry’][‘location’])
# Strip lat/long coordinates from XML
if __name__ == ‘__main__’:
parser = argparse.ArgumentParser(description=’City Geocode Search’)
parser.add_argument(‘–city’, action=”store”, dest=”city”, required=True)
given_args = parser.parse_args()
# print “Finding geographic coordinates of %s” %given_args.city
find_lat_long(given_args.city)


保持並運行指令碼


[email protected]:~/python# python 6_2_googlemap.py –city “New York”
{u’lat’: 40.7127837, u’lng’: -74.0059413}
[email protected]:~/python#

本文出自 “瑞航啟程--下一代公司專屬應用程式” 部落格,謝絕轉載!

Python查詢一個城市的Google地圖的經度和緯度

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.