2014-02-11 5 views
0

이전에 다른 웹 애플리케이션 용으로 작성한 코드를 다른 곳에서 사용했습니다. 그러나 명백한 이유는 검색 아니에요 결과 :Google지도 지오 코딩 및 ZERO_RESULTS

지오는 다음과 같은 이유로 실패했습니다 : ZERO_RESULTS

나는 다음과 같은 코드, 한 - 묵시적으로이 - 아무런 문제없이 작동을 다른 곳에서 :

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> 
<script type="text/javascript"> 
    function googleMaps (lat, lng, zoom) { 
     geocoder = new google.maps.Geocoder(); 
     var myLatlng = new google.maps.LatLng(lat, lng); 
     var myOptions = { 
      zoom: zoom, 
      center: myLatlng, 
      mapTypeId: google.maps.MapTypeId.TERRAIN 
     } 
     map = new google.maps.Map(document.getElementById("map-locations"), myOptions); 
     var marker = new google.maps.Marker({ 
      position: myLatlng, 
      map: map 
     }); 
     google.maps.event.addListener(map, "center_changed", function(){ 
      document.getElementById("latitude").value = map.getCenter().lat(); 
      document.getElementById("longitude").value = map.getCenter().lng(); 
      marker.setPosition(map.getCenter()); 
      document.getElementById("zoom").value = map.getZoom(); 
     }); 
     google.maps.event.addListener(map, "zoom_changed", function(){ 
      document.getElementById("zoom").value = map.getZoom(); 
     }); 
    } 
    $(document).ready(function() { 
     googleMaps(52.3555, -1.1743, 6); 
    }); 
</script> 
<script> 
    $(document).ready(function(){ 
     $("#address").change(function(){ 
      geocoder.geocode({ 
       "address": $(this).attr("value") 
      }, function(results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 
        map.setZoom(14); 
        map.setCenter(results[0].geometry.location); 
       } else { 
        alert("Geocode was not successful for the following reason: " + status); 
       } 
      }); 
     }); 
    }) 
</script> 

"canvas"와 해당 주소 필드도 있습니다. 다른 곳에서는 작동하는 버전과 동일합니다.

제쳐두고, Google API 절차를 거쳐 API 키를 만들었습니다.이 키는 이전 버전과 관련이없는 것처럼 보입니다. 그러나 API 키가 있거나 없으면 작동하지 않습니다.

그래서이 프로세스가 어떻게 든 문제가 있는지 궁금합니다.

+0

질문'ZERO_RESULTS 그것을 반환 할 때? 유효한 우편 주소입니까? – geocodezip

+0

내가 시도한 모든 주소 또는 우편 번호는 위의 코드와 함께 실패한 다른 웹 응용 프로그램에서 결과를 검색합니다. –

+0

이전 답변을 이해할 수 없으므로 삭제했습니다 (지오 코더가 해당 좌표의 결과로 호출되지 않았 음을 인식하지 못 했으므로 읽어야합니다). 위에서 언급 한 $ (this) .attr ("value")를 경고하고 주소/코디네이트가 실제로 유효한 방식으로 통화에 전달되는지 확인하십시오. – Swires

답변

4

당신은 $("#address").val() 대신 $("#address").attr("value") 사용

... 
geocoder.geocode({ 
       "address": $("#address").val() 
      }, function(results, status) { 
... 

에 코드를 변경해야합니다.

업데이트 :도 참조 SO ("값")`$의 값이 (이) .attr 무엇 jQuery $obj.val() vs $obj.attr(“value”)

+0

이상 응용 프로그램은 동일한 코드와 동일한 버전의 jQuery를 사용하고 있습니다. 어쨌든, 그 일을하고 있습니다! –

+0

@WayneSmallman : 설명을 보려면 링크의 답변을 확인하십시오. –