2

I am trying to make a request to directions api from android. I have constructed my request url like below:

https://maps.googleapis.com/maps/api/directions/json?mode=driving&transit_routing_preference=less_driving&origin=12.84938,77.6554783&destination=151,+9th+Main+Road,+HSR+Layout+Sector+6,+Bengaluru,+Karnataka+560102&key=MYAPI_KEY

but on testing the endpoint, I get this error:

{
   "error_message" : "This IP, site or mobile application is not authorized to use this API key. Request received from IP address 223.227.127.66, with empty referer",
   "routes" : [],
   "status" : "REQUEST_DENIED"
}

I have looked at other questions similar to this and there's a mention of server key and browser key. How do I obtain a server key? Isn't it the same as the api key I receive on registering directions or maps api?

Thanks for any help.

Andromeda
  • 230
  • 1
  • 7
  • 22
  • 1
    The directions web api is not really meant to be used directly in a mobile app. You can use an unsecured server key in the app if this is just for fun, but for a production app you should use a proxy server, which would be your own server that sends requests to the directions web api (your app can query your server endpoint, which would query the directions web api, and then send your app the results). See here for more info: https://mapsplatform.googleblog.com/2016/09/making-most-of-google-maps-web-service.html – Daniel Nugent Jun 09 '18 at 00:12
  • Thanks Daniel. If I created a Nodejs server that hits up that same endpoint and my client app (android) makes a req to an endpoint provided by the server, will it work? – Andromeda Jun 09 '18 at 00:21
  • I mean like this --- 1. Server--make req to Dir API with my apikey. 2. Client makes Req to Endpoint provided by server--- – Andromeda Jun 09 '18 at 00:22
  • @Andromeda did you find the solution for this? I am facing the same issue – YLS Oct 15 '18 at 11:45

1 Answers1

0
  • Make sure Application restriction is "none" in Developer console..
  • Direction API need IP restriction, by using Android if you give Android restriction it will respond as "request_denied"

  • SO you need Intermediate server and then you need to restrict using server IP..

  • So give restriction as none.
Navin Kumar
  • 3,393
  • 3
  • 21
  • 46