0

Possible Duplicate:
json with google geocoding api
json Uncaught SyntaxError: Unexpected token :

$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=?', function(data) {
    console.log(data);
});

It gives me this error: Uncaught SyntaxError: Unexpected token :

Community
  • 1
  • 1
user12345
  • 2,400
  • 8
  • 33
  • 40
  • 8
    http://stackoverflow.com/questions/7936610/json-uncaught-syntaxerror-unexpected-token **or** http://stackoverflow.com/questions/3143698/uncaught-syntaxerror-unexpected-token **or** http://stackoverflow.com/questions/6590608/jquery-getjson-uncaught-syntaxerror-unexpected-token-error – Tats_innit Jun 30 '12 at 09:41
  • Use the network section of your web inspector (because you're using one, aren't you?) to get the response and understand the problem. Then post it here. – MaxArt Jun 30 '12 at 09:45
  • 2
    Tats is correct http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=test shows `{...}` (instead of `test({..})`). – Rob W Jun 30 '12 at 09:46

1 Answers1

0

You are trying to get a JSONP response from google maps , which it doesnt support.

Try this instead,

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

<script>  
    $(function(){   
        var geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(40.714224,-73.961452);
        geocoder.geocode(
            {latLng  : latlng }, 
            function(dataObject, statusObject) {
                console.log(dataObject);
            }
        );
    });
</script>
Jashwant
  • 28,410
  • 16
  • 70
  • 105