2014-01-07 2 views
0

잠시 동안 다음 코드를 사용하고 있으며 작동이 멈추고 오류가 발생하는 것으로 나타났습니다. 경고는 null이라고 말합니다. 지도 API가 변경 되었습니까? 난 그냥 1로 고해상도에서 0을 변경, https://maps.googleapis.com/maps/api/js?sensor=falsehttps://maps.gstatic.com/intl/en_us/mapfiles/api-3/15/5/main.jsGoogle Maps null API를 반환하는 API (작업에 사용됨)

function geo(){ 
    if(navigator.geolocation) { 
     var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000); 
     navigator.geolocation.getCurrentPosition(
      function (pos) { 
       clearTimeout(fallback); 
       console.log('pos', pos); 
       var point = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude); 
       new google.maps.Geocoder().geocode({'latLng': point}, function (res, status) { 
        if(status == google.maps.GeocoderStatus.OK && typeof res[0] !== 'undefined') { 
         var zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/); 
alert(zip); 
         var homecity; 
         var homezip; 

         if((zip[1]>21201)&&(zip[1]<21298)) { 
           //document.getElementById('geo').innerHTML = "Baltimore "+zip[1]; 
           homecity = "Baltimore"; 
           homezip = zip[1]; 
           //$("._res").html(homecity+" "+homezip); 
           window.location.href = "?city="+homecity+"&zip="+homezip; 
         } 
         if((zip[1]>20001)&&(zip[1]<20886)) { 
           //document.getElementById('geo').innerHTML = "Baltimore "+zip[1]; 
           homecity = "D.C."; 
           homezip = zip[1]; 
           //$("._res").html(homecity+" "+homezip); 
           window.location.href = "?city="+homecity+"&zip="+homezip; 
         } 
         if((zip[1]>19019)&&(zip[1]<19255)) { 
           //document.getElementById('geo').innerHTML = "Baltimore "+zip[1]; 
           homecity = "Philadephia"; 
           homezip = zip[1]; 
           //$("._res").html(homecity+" "+homezip); 
           window.location.href = "?city="+homecity+"&zip="+homezip; 
         } 


        } 
       }); 
      }, function(err) { 
       fail(err.message+" WTF"); 
      } 
     ); 
    } 
+0

당신이 어떤 브라우저를 작업중인? 참고 : [this] (http://stackoverflow.com/questions/18980037/navigator-geolocation-getcurrentposition-not-working) 및 [해당] (http://stackoverflow.com/questions/3397585/navigator-geolocation-getcurrentposition -sometimes-works-sometimes-doesnt) – Raptor

+0

나는 최신 공개 Chrome을 사용 중입니다. –

답변

0

간단한 수정을로드 한 :

  var zip = res[1].formatted_address.match(/,\s\w{2}\s(\d{5})/);