2012-06-30 45 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-unexpected-token **或** http://stackoverflow.com/questions/6590608/jquery-getjson-uncaught-syntaxerror-unexpected-token-error –

+0

使用網絡檢查器的網絡部分(因爲你正在使用一個,是不是?)得到迴應並理解問題。然後張貼在這裏。 – MaxArt

+2

Tats是正確的http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true&callback=test顯示'{...}'(而不是'test({.. })')。 –

回答

0

您正在試圖從谷歌地圖,其中它不支持JSONP響應。

試試這個,

<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>