1

I am trying to use the Google Directions API without success. I activated the Google Maps SDK for iOS on the developer console and also the Directions API.

This is the URL I am using:

https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=API_KEY

And I am getting the This IP, site , or mobile application is not authorized to use this API Key.

The key I am using is the iOS API Key.

enter image description here

I saw in a few other questions about this problem that it may be about the iOS API key and browser API Key. I haven't tried with the browser API Key because of this question that is almost the same as mine: no result for query directions API iOS

Could someone point me on the right path or tell me what am I missing?

enter image description here

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Jose Luis
  • 3,307
  • 3
  • 36
  • 53

2 Answers2

3

Your url has not attached the API KEY correctly:

https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=API_KEY

response

{
   "error_message" : "The provided API key is invalid.",
   "routes" : [],
   "status" : "REQUEST_DENIED"
}

API_KEY is not valid, if you leave it blank or you put a correct key you will get results: https://maps.googleapis.com/maps/api/directions/json?origin=48.581380,7.767050&destination=48.581100,7.766790&key=

response

{
   "routes" : [
      {
         "bounds" : {
            "northeast" : {
               "lat" : 48.5813851,
               "lng" : 7.7670545
            },
            "southwest" : {
               "lat" : 48.5810993,
               "lng" : 7.7667977
            }
         },
         "copyrights" : "Datos de mapas ©2015 Google",
         "legs" : [
            {
               "distance" : {
                  "text" : "39 m",
                  "value" : 39
               },
               "duration" : {
                  "text" : "1 min",
                  "value" : 6
               },
               "end_address" : "Strasbourg University, 6 Rue Blaise Pascal, 67000 Strasbourg, Francia",
               "end_location" : {
                  "lat" : 48.5810993,
                  "lng" : 7.7667977
               },

// continues json answer....

Sorry If this is a variable in your app, or a typo...

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • I actually don't put "API_KEY" on my link. I put that on the question because I didn't want to give it away. I haven't tried NOT putting a key, It is a good idea. I'll try now and tell you if that worked. – Jose Luis Mar 26 '15 at 12:20
  • Well without a key it works (not surprisingly) but I do not understand why my key is not accepted... Do you have any other ideas about that? I will vote up your answer and if there are no other suggestions from others I will accept it. – Jose Luis Mar 26 '15 at 12:24
  • Your key is not valid, but i can't see why. Ckeck it, is the only reason you cannot see the map in your app. – Jordi Castilla Mar 26 '15 at 12:27
0

I was also struggling with the same problem. After following all the basic steps, this is what that helped me.

  1. While creating API key, put application restrictions to 'None', API restrictions to 'Restrict key' and add Directions API, Places API and Maps SDK for iOS. Don't forget to 'SAVE' the changes.
  2. Add your API key to AppDelegate.swift file
  3. In the code, add this API key to the URL string
  4. Save the file, clean the build and run the application
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103