2010-05-28 3 views
2

내 좌표가 있습니다. 이제 마커의 주소를 얻고 싶습니다. 그래서 웹을 검색하여 google maps reserve geocode를 찾았습니다.Google지도 - Reserve Geocode -> 오류 "invalid label"

invalid label 

"status": "OK",\n 

에 :

$.getJSON('http://maps.google.com/maps/api/geocode/json?latlng='+point.lat()+','+ point.lng() +'&key='+apiKey+'&sensor=false&output=json&callback=?', 
function(data) { 
    console.log(data); 
}); 

내가 JSON을 점점 의미하는 주소를 표시하려고 불을 지르고 다음과 같은 오류가 발생합니다 : 는 이제 다음을 수행하려 많이 찾았지만 문제를 해결하는 답을 찾지 못했습니다. 내 코드에 무슨 문제가 있다고 말할 수 있습니까?

좌표에 대한 주소 데이터를 가져 오는 다른 방법이 있습니까?

답변

4

same origin policy에 의해 차단 될 수 있습니다. 어제 나는이 주제에 대해 a similar question라고 대답했는데, 체크 아웃하는 것이 좋습니다.

Google지도에서 자바 스크립트 용으로 전체 기능이 제공된 Client-side Geocoding API을 제공하는 경우 Server-side Geocoding Web Service을 사용하려고합니다. v2 version도 있지만 최근에는 사용되지 않습니다.

이것은 동일한 출처 문제를 자동으로 해결하며, 서버 IP 주소 대신 클라이언트 IP 주소별로 요청 제한이 계산되므로 인기있는 사이트에 큰 차이가 발생할 수 있습니다.

클라이언트 측 서비스는 매우 사용하기 쉬워야합니다. 위의 예는 콘솔에 Lambeth, Greater London SE1 7, UK를 인쇄해야

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

<script type="text/javascript">  
    var geocoder = new google.maps.Geocoder(); 
    var point = new google.maps.LatLng(51.50, -0.12); 

    if (geocoder) { 
     geocoder.geocode({ 'latLng': point }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      if (results[1]) { 
       console.log(results[1].formatted_address); 
      } 
      else { 
       console.log('No results found'); 
      } 
     } 
     else { 
      console.log('Geocoder failed due to: ' + status); 
     } 
     }); 
    }  
</script> 

다음은 V3 API를 사용하여 매우 간단한 역 지오 코딩 예제이다.

1

내가 찾던 답변에 대해 감사드립니다. 여기에 사소한 변경이 필요하다고 생각하면 은 results[0]이어야합니다. 그렇지 않으면 "이웃"주소가 표시됩니다. 완전한이 같아야

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

<script type="text/javascript">  
    var geocoder = new google.maps.Geocoder(); 
    var point = new google.maps.LatLng(23.7442812,90.3728129); 

    if (geocoder) { 
     geocoder.geocode({ 'latLng': point }, function (results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      if (results[0]) { 
       console.log(results[0].formatted_address); 
      } 
      else { 
       console.log('No results found'); 
      } 
     } 
     else { 
      console.log('Geocoder failed due to: ' + status); 
     } 
     }); 
    }  
</script> 

출력 콘솔에 도시한다

, Road No 8A, Dhaka, Bangladesh