2014-10-01 2 views
0

주소 (여기서는 Google 본사)를 지오 코딩하려고합니다. 예기치 않은 토큰 : :입니다 :Google지도 API에서 JSON을 파싱했습니다.

내가 어디 예상치 못한 알아낼 수 없습니다

내가 JSON을 얻을 수있는 jQuery를 $.ajax() 요청을 만들려고

, 그것은 catch되지 않은 구문 에러는 말한다. 내가하려고하는 것은 위도와 경도를 문자열에서 디코드 한 다음 Places API를 사용하여 좌표 근처의 메 커닉을 찾는 것입니다.

$.ajax({ 
    url: 'https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=myKey', 
    dataType: 'jsonp', 
    jsonp: 'callback', 
    method: 'GET', 
    success: function(results){ 
     console.log(results); 
     queryLat = results['results']['geometry']['location']['lat']; 
     queryLong = results['results']['geometry']['location']['lng']; 
     console.log('latitude: '+queryLat); 
     console.log('longitude: '+queryLong); 


     function callback(mapsResults, status){ 
      if(status == google.maps.places.PlacesServiceStatus.OK){ 
       for(var i = 0; i < mapResults.length; i++){ 
        var place = mapResultsi]; 
        createMarker(mapResults[i]); 
       } 
      } 
     } 
     var map; 
     var service; 

     map = new google.maps.Map(document.getElementById('map'), { 
      center: new google.maps.LatLng(queryLat, queryLong), 
      zoom: 15 
     }); 

     var request ={ 
      location: new google.maps.LatLng(queryLat, queryLong) 
      radius:'500', 
      query:'mechanic' 
     }; 

     service = new google.maps.places.PlacesService(map); 
     service.textSearch(request, callback); 
}); 
+1

'var place = mapResults [i];' –

+1

그리고'location : new google.maps.LatLng (queryLat, queryLong)'뒤에 쉼표가 누락되었습니다. –

+0

@PaulRoub Thanks . – wordSmith

답변

1

세 가지 문제 : 당신이 location: new google.maps.LatLng(queryLat, queryLong) 후 쉼표 누락 JSON을 반환하는 API

  • var place = mapResultsi];해야 var place = mapResults[i];
  • 를 호출 할 때

    1. jsonp을 기대하는 $.ajax()을 말하는
  • 0
    function callback(mapsResults, status){ 
          if(status == google.maps.places.PlacesServiceStatus.OK){ 
           for(var i = 0; i < mapResults.length; i++){ 
            **var place = mapResultsi];** 
            createMarker(mapResults[i]); 
           } 
          } 
         } 
    
    관련 문제