2013-03-20 30 views
0

好了,我已經建立了一個工作(幾乎)地理編碼器,它接受一個地址或經/緯度組合,並建議成果在這裏看到:地理編碼返回ZERO_RESULT和QUERY_LIMIT_REACHED

$(this).autocomplete({ 

     source:function (request, response) { 

      if (geocoder == null) { 
       geocoder = new google.maps.Geocoder(); 
      } 
      geocoder.geocode({'address':request.term }, function (results, status) { 

       if (status == google.maps.GeocoderStatus.OK) { 
        var searchLoc = results[0].geometry.location; 
        var lat = results[0].geometry.location.lat(); 
        var lng = results[0].geometry.location.lng(); 
        var latlng = new google.maps.LatLng(lat, lng); 
        var bounds = results[0].geometry.bounds; 

        geocoder.geocode({'latLng':latlng}, function (results1, status1) { 
         if (status1 == google.maps.GeocoderStatus.OK) { 
          if (results1[1]) { 
           response($.map(results1, function (loc) { 
            return { 
             label:loc.formatted_address, 
             lat:lat, 
             lng:lng, 
             value:loc.formatted_address, 
             bounds:loc.geometry.bounds 
            } 
           })); 
          } 
         } 
        }); 
       } 
      }); 
     }, 

和90%的它的工作時間非常有效。但是,我現在注意到,偶爾會在彈出式列表中返回的第一個項目不可點擊。我已經爲變量status設置了日誌,並且注意到偶爾會出現ZERO_RESULTQUERY_LIMIT_REACHED。在這兩種情況下,列表都會加載值,列表中的所有內容都是可選的,但第一種情況除外。任何想法可能的解決方案?

回答

0

看起來好像有一些情況,其中bounds被API忽略,因此在我的代碼中被定義爲undefined。這導致代碼進一步下降了javascript問題,並阻止滿足條件。它看起來像甚至不需要正確地框架地圖,我已經解決了我的問題...

相關問題