跳转到主要内容

Python的HERE位置服务

项目描述

Python的HERE位置服务

Tests Documentation Status codecov PyPI - Status PyPI - Python Version PyPI - Python Version PyPI - License Downloads Conda (channel only) Conda Downloads Anaconda-Server Badge Binder

用于HERE位置服务的Python客户端。

用法

使用HERE Geocoding & Search API进行地理编码.

Geocoding Example

使用HERE Isoline Routing API进行等高线绘制.

Isolines Example

先决条件

在您安装 HERE Location Services for Python、运行测试套件或使用示例笔记本之前,请确保您满足以下先决条件

  • 一个Python安装,推荐版本为3.6+,并且有 pip 命令来安装依赖项。
  • 为了使用位置服务API,需要进行身份验证。有两种身份验证方式
    • 使用API密钥进行身份验证

      • 对于基于API密钥的身份验证,您需要一个HERE开发者账户,可以在HERE开发者门户免费获取。
      • HERE开发者门户获取的API密钥,在名为 LS_API_KEY 的环境变量中设置,例如(当然,使用有效的值)
        $ export LS_API_KEY="MY-LS-API-KEY"
        
    • 基于OAuth令牌的身份验证

      • 对于OAuth令牌认证,您需要在HERE平台拥有一个账户。有关HERE平台账户的更多信息,请查看我们的文档获取HERE账户。一旦您拥有账户,请按照以下步骤获取凭证
      • 前往HERE平台应用程序和密钥并注册一个新的应用程序。
      • 为应用程序创建一个密钥,并下载生成的credentials.properties文件。

      HERE平台生成的应用程序凭证应类似于以下示例

      here.user.id = <example_here>
      here.client.id = <example_here>
      here.access.key.id = <example_here>
      here.access.key.secret = <example_here>
      here.token.endpoint.url = <example_here>
      

      您可以使用以下任何一种方法提供您的凭证

      • 默认凭证
      • 环境变量
      • 凭证文件

      默认凭证

      将凭证文件放置于

      对于Linux/MacOS: $HOME/.here/credentials.properties

      对于Windows: %USERPROFILE%\.here\credentials.properties 创建LS对象的代码片段

      from here_location_services import LS
      
      # platform credentials will be picked from the default credentials file's location mentioned above
      # and api_key should not be set in env variable LS_API_KEY.
      ls = LS()
      

      环境变量

      您可以通过设置以下环境变量的值来覆盖默认凭证

      HERE_USER_ID
      HERE_CLIENT_ID
      HERE_ACCESS_KEY_ID
      HERE_ACCESS_KEY_SECRET
      HERE_TOKEN_ENDPOINT_URL
      

      创建LS对象的代码片段

      from here_location_services import LS
      from here_location_services import PlatformCredentials
      
      ls = LS(platform_credentials=PlatformCredentials.from_env()) 
      

      凭证文件

      您可以将任何凭证文件指定为替代~/.here/credentials.properties中找到的文件。如果路径中不存在文件,或者文件格式不正确,则会生成错误。创建LS对象的代码片段

      from here_location_services import LS
      from here_location_services import PlatformCredentials
      
      platform_credentials = PlatformCredentials.from_credentials_file("<Path_to_file>")
      ls = LS(platform_credentials=platform_credentials) 
      

安装

  • 使用以下命令从Anaconda conda-forge频道安装HERE Location Services for Python

    $ conda install -c conda-forge here-location-services
    
  • 使用以下命令从PyPI安装HERE Location Services for Python

    $ pip install here-location-services
    
  • 使用以下命令从GitHub安装HERE Location Services for Python

    $ pip install -e git+https://github.com/heremaps/here-location-services-python#egg=here-location-services
    

运行测试套件

使用以下命令运行测试套件

$ pip install -r requirements_dev.txt
$ pytest -v --cov=here_location_services tests

文档

文档可在此处查看这里

运行以下命令以在本地构建文档

$ pip install -e .
$ pip install -r requirements_dev.txt
$ sh scripts/build_docs.sh

Hello World示例

以下是一些微型“Hello World”样例,您可以在安装后立即运行以获得成功的XYZ体验!

使用API密钥

import json
import os

from here_location_services import LS


LS_API_KEY = os.environ.get("LS_API_KEY")  # Get API KEY from environment.
ls = LS(api_key=LS_API_KEY)

address = "Invalidenstr 116, 10115 Berlin, Germany"
geo = ls.geocode(query=address)
print(json.dumps(geo.to_geojson(), indent=2, sort_keys=True))

使用OAuth令牌

import json

from here_location_services import LS
from here_location_services import PlatformCredentials

credentials = PlatformCredentials.from_default()
ls = LS(platform_credentials=credentials)

address = "Invalidenstr 116, 10115 Berlin, Germany"
geo = ls.geocode(query=address)
print(json.dumps(geo.to_geojson(), indent=2, sort_keys=True))

许可协议

版权(C)2019-2021 HERE Europe B.V.

有关许可证详细信息,请参阅此项目根目录中的许可证文件

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分布

here-location-services-0.4.0.tar.gz (54.9 kB 查看哈希值)

上传时间

构建分布

here_location_services-0.4.0-py2.py3-none-any.whl (58.1 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持