Python查询一个城市的谷歌地图的经度和纬度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python查询一个城市的谷歌地图的经度和纬度相关的知识,希望对你有一定的参考价值。


Python查询一个城市的谷歌地图的经度和纬度


设置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查询一个城市的谷歌地图的经度和纬度的主要内容,如果未能解决你的问题,请参考以下文章

如何从 ionic 2 中的谷歌地图获取纬度和经度?

两个纬度/经度点之间的谷歌地图距离计算?

如何在不使用 Xcode、iPhone 中的谷歌地图的情况下从地址获取纬度和经度

尽管准确的纬度/经度,但是〜100米的谷歌地图嵌入不正确

在谷歌地图中隐藏纬度和经度

在谷歌地图 api v3 中将地区、城市、州、国家/地区转换为纬度和经度?