8
votes

I was trying to use Google Distance Matrix API JSON in my project, after formatting the url, for example:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&destinations=San+Francisco|Victoria+BC&mode=bicycling&language=en&sensor=false

I was able to view the result in browser, but when I tried to make a http request to get the result, I will receive status : REQUEST_DENIED

In documentation:

REQUEST_DENIED indicates that the service denied use of the Distance Matrix service by your application.

But I still don't know why my request is denied. More Info from google:

Use of the Distance Matrix API must relate to the display of information on a Google Map; for example, to determine origin-destination pairs that fall within a specific driving time from one another, before requesting and displaying those destinations on a map. Use of the service in an application that doesn't display a Google map is prohibited.

If I can't get the result, how can I apply it on google map? Anyone with same problem? I will post sample code later, to clarify my question more clearly.

6

6 Answers

4
votes

I had a similar problem, but it was due to assuming that the sensor tag would default to false, but it is in fact required.

2
votes

Google Distance Matrix API has a limit of elements set to 2500. I highly doubt it that you would have gone over this limit, as you would have to have calculated the maximum 10 x 10 matrix 25 times over. I am from South Africa, and it refused to work for any local addresses until I changed the transport mode to driving (from walking, I mean seriously, we have cars). Maybe that'll help

0
votes

I had the same problem earlier.

you need to check out with the Google Api key version and codes/scripts of version you are using.

0
votes
0
votes

First thing is that you need is to have an API key assigned to your application. This is done first by creating it in the Google API Manager at [https://console.developers.google.com/]. After that you'll be free to face new issues :)

0
votes

You need to set an API KEY for using Google map services like this:

https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=**YOUR_API_KEY**