-1

What I have in Python:

import requests
url_osrm = 'http://router.project-osrm.org/viaroute?loc=50.12345,8.12345&loc=50.23456,8.23456'
print url_osrm
proxies = {"http": "http://YOUR-PROXY:8080"}
osrm = requests.get(url_osrm, proxies=proxies)
print osrm.text

Question A: How many requests can I send until I get blocked?


Question B: How can I extract the first lon/lat from the json-output?

  • 1
    Please edit your question and only ask one question at a time. Ask a additional question for your second question. – ustroetz Oct 21 '13 at 16:59
1

Question A: How many requests can I send until I get blocked?

There is not a fixed limit. It is recommended to use a valid user-agent that you register before hand. This way it is less likely to get blocked. So write an Email to OSRM (infoATproject-osrm.org), explain them what you want to do, and give them the name of your user-agent.

In your python code this will look like this:

import requests
start = '50.12345,8.12345'
stop = '50.23456,8.23456'

headers = {'User-Agent': 'Your User-Agent verification'}
url = 'http://router.project-osrm.org/viaroute?loc=' + start + '&loc=' + stop
response = requests.get(url, headers=headers)

Question B: How can I extract the first lon/lat from the json-output?

To get the entire json:

data = response.json()

To get the via_points:

via_points = data['via_points']

To get the first one:

first_point = via_points[0]
print first_point
>>> 
[50.123558, 8.123524]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.