2017-07-27 13 views
0

私のコードは既に書かれていますので、標準偏差とカーブスムージングを使用して、GPSポイントの速度と距離の値を求めます。 SnapToRoadsにリクエストを送信し、APIキーリンクに表示される値のセットを取得する必要があります。 次に、標準偏差、曲線平滑化、およびAPIの3つの方法の範囲内の点の値の交差を取得したいと思います。SnapToRoads APIから緯度と経度のデータをリクエストするにはどうすればよいですか?

HTTPリクエストの作成方法はわかりません。タプルformate |緯度、経度|。 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) 
関連する問題