tags:

views:

20

answers:

1

Hi,

I am trying to get json from google map api using ajax and jquery.

The code is something like

     url: "('http://maps.google.com/maps/api/geocode/json?address=559/1,+9th cross+7th main+Gokula,+1st stage+bangalore,+Karnataka,+India&sensor=false')",
     type: "POST",
     dataType: "jsonp",
     success: function(longlatJson) {
         var jsonObj = JSON.parse(JSON.stringify(longlatJson));

         var lat = jsonObj.results[0].geometry.location.lat;
         var long = jsonObj.results[0].geometry.location.lng;
         var latlng = new google.maps.LatLng(lat, long);

         map.panTo(latlng);
                 },

I am failed to get the result. I mean it is coming out of the success function.

Can anyone help me to resovlethis?

Regards, Mahesh

A: 

I'll mention this first because it really trumps all other problems, Google removed JSONP support in V3 of the GeoEncode service, so you can't make a cross-domain request like you're attempting to it anymore.

These are the other problems here that I see:

  • There's no reason to encode/decode the response it should already be an object (jQuery's doing the work here).
  • Your URL is wrapped in (' and '), these should be removed.
  • You're missing an API key &key=somethinghere, I'm not sure what the behavior is when this is missing as I don't use google services like this much.
Nick Craver