2017-07-27 84 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)