Reputation: 83
I'm trying to use the Google distance matrix API, and search the time to travel from one gps point to an other. I tried:
import urllib.request as url
API_KEY = "*********************"
orig_coord = "45.6492,4.7946"
dest_coord = "45.6403,4.7221"
mode = "bicycling"
url_request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}s&mode={2}&language=fr-FR&key={3}".format(orig_coord, dest_coord, mode, API_KEY)
result = url.urlopen(url_request)
Here is what my result looks like:
{
"destination_addresses" : [ "45 Claude Lane, Spartanburg, Caroline du Sud 29307, \xc3\x89tats-Unis" ],
"origin_addresses" : [ "45.6492,4.7946" ],
"rows" : [
{
"elements" : [
{
"status" : "ZERO_RESULTS"
}
]
}
],
"status" : "OK"
}'
It looks like the API does not unerstand that I'm gaving GPS coordinate and not adress, thank's for your help
Upvotes: 2
Views: 1392
Reputation: 168
You have a typo in your code. Here's the correct version.
url_request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}&mode={2}&language=en-EN&key={3}".format(orig_coord, dest_coord, mode, API_KEY)
Upvotes: 1
Reputation: 4912
Your code looks good to me, unless your API_KEY is wrong.
Try this:
import requests
API_KEY = "*********************"
orig_coord = "45.6492,4.7946"
dest_coord = "45.6403,4.7221"
mode = "bicycling"
url_request = "https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}&destinations={1}s&mode={2}&language=fr-FR&key={3}".format(orig_coord, dest_coord, mode, API_KEY)
rsp = requests.get(url_request)
print rsp.status_code
print rsp.text.encode('utf-8')
You will see data you want or error message.
Here is link for google distance matrix api. Hope it helps.
Upvotes: 1