8

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.

Mark McDonald
  • 7,571
  • 6
  • 46
  • 53
wgx731
  • 197
  • 3
  • 15

8 Answers8

4

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.

zachaysan
  • 1,726
  • 16
  • 32
2

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

sirwoetang
  • 31
  • 3
1

https://maps.googleapis.com/maps/api/distancematrix/json?origins=Seattle&destinations=San+Francisco&key=YOUR_API_KEY

Please make sure that you have created a credentials on Google Console which can be called as "API KEY" and you are using this API KEY in above request URL on the place of "YOUR_API_KEY"

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • This doesn't add anything to [this answer](https://stackoverflow.com/a/43280914/5211833) posted already five years ago – Adriaan Sep 27 '22 at 12:26
0

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

First thing is that you need is to have an API key assigned to your application. This is done by creating it in the Google API Manager.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
0

I believe you need to get a Google Maps API key

Gonja
  • 101
  • 1
0

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**
MK-rou
  • 686
  • 2
  • 9
  • 30
0

I hope your have enabled distance matrix API from google console for your application.

please refer

https://support.google.com/googleapi/answer/6158841?hl=en

along with this you can restrict API_KEY for unauthorized use.