google地图平台的python客户端库
googlemaps的Python项目详细描述
谷歌地图服务的Python客户端
说明
使用python?想用地理编码吗?寻找方向? 也许是方向矩阵?这个库带来了google地图平台web 为您的python应用程序提供服务。
Google Maps服务的Python客户机是以下googlemaps的Python客户机库 原料药:
- 方向API
- 距离矩阵API
- 立面图API
- 地理编码api
- 地理定位API
- 时区API
- 道路API
- 地点API
记住同样的terms and conditions适用 当通过这个库访问这些api时使用它们
支架
这个图书馆是社区支持的我们对 我们希望您在其上构建实际生产应用程序的库。我们会尽力支持, 通过堆栈溢出,库的公共和受保护的表面保持向后 将来的兼容性;但是,当库是0.x版时,我们保留 做向后不相容的改变如果我们删除了一些功能(通常是因为 更好的功能存在或如果功能被证明是不可行的,我们的意图是贬低。 给开发人员一年时间来更新他们的代码
如果您发现一个bug,或者有一个功能建议,请记录一个问题。如果你愿意 投稿,请阅读投稿。
要求
- Python2.7或更高版本。
- 一个Google Maps API密钥
API键
每个Google Maps Web服务请求都需要一个API密钥或客户端ID.API密钥 在Google Cloud console的“api&services”选项卡的“credentials”页中生成。
有关开始使用Google Maps平台和生成/限制API密钥的更多信息,请参见文档中的Get Started with Google Maps Platform
重要信息:此密钥应在服务器上保密
安装
$ pip install -U googlemaps
请注意,如果要指定连接/读取超时,则需要请求2.4.0或更高版本
用法
本例使用地理编码API和带有API密钥的方向API:
importgooglemapsfromdatetimeimportdatetimegmaps=googlemaps.Client(key='Add Your Key here')# Geocoding an addressgeocode_result=gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')# Look up an address with reverse geocodingreverse_geocode_result=gmaps.reverse_geocode((40.714224,-73.961452))# Request directions via public transitnow=datetime.now()directions_result=gmaps.directions("Sydney Town Hall","Parramatta, NSW",mode="transit",departure_time=now)
下面是相同的示例,使用客户端ID和客户端机密(数字签名)
用于身份验证这段代码假设您之前已经加载了client_id
以及具有适当值的client_secret
变量
有关如何生成client_secret
(数字签名)的指南,请参见
正在使用的api的文档。例如,有关
Directions API
gmaps=googlemaps.Client(client_id=client_id,client_secret=client_secret)# Geocoding and addressgeocode_result=gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')# Look up an address with reverse geocodingreverse_geocode_result=gmaps.reverse_geocode((40.714224,-73.961452))# Request directions via public transitnow=datetime.now()directions_result=gmaps.directions("Sydney Town Hall","Parramatta, NSW",mode="transit",departure_time=now)
有关更多用法示例,请查看the tests
功能
失败时重试
出现间歇性故障时自动重试。也就是说,当任何可重试的5xx错误 从API返回
客户ID
谷歌地图API高级计划客户可以使用他们的客户ID和密码进行身份验证, 而不是api密钥。
建设项目
# Installing nox
$ pip install nox
# Running tests
$ nox
# Generating documentation
$ nox -e docs
# Copy docs to gh-pages
$ nox -e docs && mv docs/_build/html generated_docs && git clean -Xdi && git checkout gh-pages
文档和资源
开始
- Get Started with Google Maps Platform
- Generating/restricting an API key
- Authenticating with a client ID
API文件
- Google Maps Platform web services
- Directions API
- Distance Matrix API
- Elevation API
- Geocoding API
- Geolocation API
- Time Zone API
- Roads API
- Places API
支持
更改日志
该项目的所有显著变化都将记录在本文件中。
Unreleased
更改
添加了
移除
v3.1.1
更改
- 将变更日志添加到清单
v3.1.0
更改
- 将生成系统切换为使用nox、pytest和codecov。在测试框架中添加了Python3.7
- 设置截断的经纬度浮动to 8 decimals而不是6的精度
- 请求的最低版本已增加。
- SES公司sion令牌参数added到
place()
- 修复了
request_kwargs
中的头被重写的问题
添加了
- PyPi上传的自动化
- 包装详细说明
- 在清单和tarball中添加了测试。
移除
- 删除了可以用
uuid.uuid4().hex
替换的位置places_autocomplete_session_token
- 已删除不推荐的
places_radar
。
注意:更改日志的开始时间是2019-08-27,v3.0.2。