2014-01-23 7 views
0

저는 지오 코더를 사용하여 우편 번호를 기반으로 위치를 얻고 있습니다 (미국에만 국한 됨). 유효하지 않은 우편 번호 (예 : 90123)를 입력하면 ZERO_RESULTS 대신 기본값으로 제공됩니다. 기본값은 텍사스 주 덴튼입니다 (모든 잘못된 코드의 경우). 이 문제를 방지하려면 어떻게해야합니까? 아니면이 문제를 피하기 위해 코드가 유효하지 않은지 여부를 말해주십시오.GeoCoder는 잘못된 우편 번호에 대한 기본값을 제공합니다.

geocoder.geocode({ 'address': zip, componentRestrictions: {country: 'us'} }, function (results, status) { 
        if (status == google.maps.GeocoderStatus.ZERO_RESULTS) { 
         jQuery('#zipErrorId').html("INVALID"); 
        } 
        if (status == google.maps.GeocoderStatus.OK) { 
         geocoder.geocode({'latLng': results[0].geometry.location}, function(results, status) { 
         if (status == google.maps.GeocoderStatus.OK) { 
          if (results[1]) { 
           var cityState = getCityState(results); 
           // like Apple Valley, Minnesota 
           var cityStateArr = cityState.split('|'); 
            --------------------------- 
          } 
         } 
        }); 
       } 

답변

0

가 현재는 보스턴, MA에 푸르덴셜 타워를 반환 :

이 코드를 사용하고 있습니다. 이유를 모르겠다.

입력 한 값을 되돌려 보냅니다. 따라서 results.address_components.short_name에서 반환 된 값이됩니다. 예를 들어 "00000, 미국"을 검색하는 경우 results.address_components.short_name은 "02199"(앞에서 언급 한 건물의 우편 번호)가됩니다. 그 값이 당신이 준 값과 일치하지 않으면 아마도 잘못된 우편 일 것입니다.

관련 문제