Question

Today I struggled with the following:

$.ajax({url:'http://maps.google.com/maps/api/geocode/jsonaddress=Karachi&sensor=false&output=json&callback=?',
        dataType: 'json',
        success: function(data){
         //eval("("+data+")");
         alert(data);
        }
});

Firefox gives the error "Invalid Label" and Chrome "Uncaught SyntaxError: Unexpected token :". I found a lot of posts about this, and I tried all kinds of things like eval(), but also:

$.getJSON('http://maps.google.com/maps/api/geocode/jsonaddress=Karachi&sensor=false&output=json&callback=?',
 function(data){
  //eval("("+data+")");
  alert(data);
 }
);

Same result. Also, other json data works fine, for instance flickr ("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?). So it has something to do with the Google Maps API output i guess..

Thanks in advance.

Was it helpful?

Solution

You just can't do it; AFAIK Geocoder V3 does not allow callback=?.
Check this thread for further information.

OTHER TIPS

You can do it in maps V3, but you can't use $.getJSON to get the data, instead there is a method in the maps api which retrives the data if you give it an address.

var  geocoder = new google.maps.Geocoder();
 geocoder.geocode( { 'address': '10 downing street, London, UK'}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        console.log(results);
        alert(results[0].geometry.location);

      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });

these links have all the info.... https://developers.google.com/maps/documentation/javascript/geocoding#GeocodingRequests

https://google-developers.appspot.com/maps/documentation/javascript/examples/geocoding-simple

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top