【问题标题】:How can I request the latitude and longitude data from SnapToRoads API?如何从 SnapToRoads API 请求纬度和经度数据?
【发布时间】:2017-07-27 13:09:46
【问题描述】:

好的,不,我的代码...已经编写好了,它使用标准偏差和曲线平滑来计算 GPS 点的速度和距离值。我需要向 SnapToRoads 发送请求并获取一组显示在 API 密钥链接上的值。 然后我想从所有三种方法中获取范围内点值的交集:标准偏差、曲线平滑和 API

我不知道如何发出 HTTP 请求,更不用说以元组格式 |Lat, Long| 获取它。 API 页面的示例数据:

{ “捕捉点”:[

{
  "location": {
    "latitude": 12.919082345679861,
    "longitude": 77.651684714045615
  },
  "originalIndex": 0,
  "placeId": "ChIJ6yP7JIIUrjsRpHSPhEcWRHc"
},
{
  "location": {
    "latitude": 12.918915069015311,
    "longitude": 77.651690053806533
  },
  "originalIndex": 1,
  "placeId": "ChIJ6yP7JIIUrjsRpHSPhEcWRHc"
},
{

]

谢谢

【问题讨论】:

  • 使用 urllib 或请求模块

标签: java python json http gps


【解决方案1】:

Python requests 对这类工作派上用场。

但在您下载并安装请求之后 你基本上是这样做的

import requests
list_of_coordinates = []
api_request = requests.get(url_to_api_endpoint)
if (api_request.status_code == 200): #verifying the request was successful
      data = api_request.json() #converts it to json/dictionary so you can key in
      #note that the json returned seems to be a dictionary that contains a list
      location_points = data['snappedPoints'] #get the list of location objects
      for coord_vals in data_points:
          coordinates =  (location_points['location']['longitude'], location_points['location']['latitude'])
          list_of_coordinates.append(coordinates)

【讨论】:

    猜你喜欢
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-07-06
    • 2011-08-21
    • 2015-02-28
    相关资源
    最近更新 更多