3

I was trying to draw directions on MKMapView after getting response from Google direction API. I am trying this as Apple server is not returning the direction result for locations in India and i found it somebody on stack overflow was facing the same issue. I was trying to do like this

    NSString *url = @"https://maps.googleapis.com/maps/api/directions/json?origin=Gurgaon&destination=Noida&key=XXXXXXXXXXXXX&sensor=true";

But i'm getting below response

{
"error_message" = "This IP, site or mobile application is not authorized to use this API key.";
routes =     (
);
status = "REQUEST_DENIED";

}

I double checked the bundle ID i'm using is matching to the one, i have provided while creating iOS Key for Google APIs. Anybody having any idea what i'm missing.

Varun Mehta
  • 1,733
  • 3
  • 18
  • 39

2 Answers2

1

It looks like Google Directions API and Google Places API doesn't support keys with iOS or Android restrictions. I've found this in Google Places API's `FAQs:

API keys with Android or iOS restrictions are not supported. Please use a generic (unrestricted) API key, or a key with browser or server restrictions.

https://developers.google.com/places/web-service/faq enter image description here

I didn't find the same info in Google Directions API docs, but I suppose that it has the same limitation as Google Places API.

A. Poltoratskyi
  • 410
  • 6
  • 13
  • This worked for me in android app while trying to use Directions API, the key was restricted to Android but i faced the error above after removing the restrictions worked fine, that is weird! – Ahmed Mousa Nov 08 '20 at 10:51
  • @AhmedMousa it your case it could be better and more secure to add one more API key for Directions API only with another type of restriction that Google support. – A. Poltoratskyi Dec 04 '20 at 17:10
  • Yes we did this and restricted this key to directions apis not (Android apps), Thank you – Ahmed Mousa Dec 05 '20 at 12:01
0

I'm in the process of figuring that out now on the Android side. Your API key does not match the package your registered. Might you be trying to use an old API key?

EDIT: Ok, I figured it out with the help of:

Maps API keys for geocoding not working anymore?

First, sign up for new iOS key like you did before in the Deverloper Console, but don't type anything in the box.

If that doesn't work you'll have received something like "This API key has expired".

Then try getting rid of the &API_KEY=klajsdblkajbsfkjvaskjghan;nbfa parameter in your URI.

It seems that when making calls with Android to Google Maps API v3 you don't need an API key so just omit that part.

Disclaimer: This works at least with a JUnit Test case like I am running, I haven't gotten it to production but I will update with results.

Good luck!

Community
  • 1
  • 1
tricknology
  • 1,092
  • 1
  • 15
  • 27