2013-03-20 27 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问题,并阻止满足条件。它看起来像甚至不需要正确地框架地图,我已经解决了我的问题...

相关问题