1

I am trying to use Google Maps API in my application. I am not able to get result out of this simple API request. A week ago this code was working perfectly. I don't know if there is a problem in the Google's service or my code.

Here is my request:

       $.ajax({
            type: "GET",
            url: apilink,
            data: {
                origin: start.replace(/ /g, '+'),
                destination: end.replace(/ /g, '+'),
                waypoints: 'optimize:true|' + waypts.join('|').replace(/ /g, '+'),
                travelMode: google.maps.DirectionsTravelMode.DRIVING,
                sensor: false
            },
            dataType: "json"
        }).done(function (response) {
        alert("inside done");
       });

Looking into my javascript console, this was my request :

https://maps.googleapis.com/maps/api/directions/json?&origin=Chennai,+Tamil+Nadu,+India&destination=New+Delhi,+Delhi,+India&waypoints=optimize:false|New+Delhi,+Delhi,+India&travelMode=DRIVING&sensor=false

Now as I open this link, I am able to see the JSON response. But I am not able to get the alert "inside done".

What has gone wrong in just few days ?

Ateev Chopra
  • 1,026
  • 2
  • 15
  • 32
  • possible duplicate of [Google Maps API Webservices](http://stackoverflow.com/questions/19776393/google-maps-api-webservices) – Dr.Molle Nov 11 '13 at 19:30

1 Answers1

1

done() is equivalent to the old success() call - this gets called only when the call succeeds. If the call fails, done callbacks will not be excuted. Always add a fail callback to ajax calls. If for nothing else, then just to remind yourself that this call can fail someday and the business rules don't yet specify what has to be done in that case.

As for your particular case, you may have hit your daily limit. It has happened to me before. Google's restrictions on the free usage are very generous when it comes to personal uses but are crippling if you are just scraping driving directions :)

Chandranshu
  • 3,669
  • 3
  • 20
  • 37
  • I tried using the error : function(){alert("error")}; and got error alert. I don't think that my daily limit has finished. I haven't' even done 10 requests. Its something else. – Ateev Chopra Nov 11 '13 at 18:01
  • @user2962766 Now that you know for sure that you are getting an error, why not enhance your error handler to tell us the exact error you are getting? Also, if you were using done() earlier, you should be using fail now. Use function(jqXHR, textStatus, errorThrown){} as the fail callback instead of the current nullary one. – Chandranshu Nov 11 '13 at 21:25
  • I´m also having this issue [link](http://stackoverflow.com/questions/19866686/ajax-get-xml-google-directions), i was using Ajax to get the XML from Google Directions and obtain some data from it, but in the last days it stopped working. Also cant get a alert when done. – azost Nov 12 '13 at 16:59