2012-06-30 3 views
0

Possible Duplicate:
json with google geocoding api
json Uncaught SyntaxError: Unexpected token :JSONP вызов дает мне ошибку

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

Это дает мне эту ошибку: Uncaught SyntaxError: Unexpected token :

+8

http://stackoverflow.com/questions/7936610/json-uncaught-syntaxerror-unexpected-token ** или ** http://stackoverflow.com/questions/ 3143698/uncaught-syntaxerror-неожиданный токен ** или ** http://stackoverflow.com/questions/6590608/jquery-getjson-uncaught-syntaxerror-unexpected-token-error –

+0

Используйте сетевой раздел вашего веб-инспектора (потому что вы используете его, не так ли?), чтобы получить ответ и понять проблему. Затем разместите его здесь. – MaxArt

+2

Таты правильные http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=test показывает '{...}' (вместо 'test ({.. }) '). –

ответ

0

Вы пытаетесь получить ответ JSONP от карт Google, которые оно не поддерживает.

Попробуйте вместо этого,

<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> 
Смежные вопросы