2017-07-27 88 views
0

好吧不,我的代码已经写好了,它使用标准偏差和曲线平滑处理GPS点的速度和距离值。我需要发送一个请求到SnapToRoads并获取一组显示在API密钥链接上的值。 然后我想从所有三种方法得到范围内的点的交集值:标准偏差,曲线平滑和API我不知道如何提出HTTP请求,更少得到它在元组合成中|经纬度|。从API页样本数据:如何从SnapToRoads API请求纬度和经度数据?

{ “snappedPoints”:

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

]

谢谢

+0

使用的urllib或请求模块 – bigbounty

回答

0

的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)