代码之家  ›  专栏  ›  技术社区  ›  Toran Billups

谷歌地图API-GClientGeocoder使用getLatLng方法不一致?

  •  0
  • Toran Billups  · 技术社区  · 16 年前

    我注意到我的地理编码器在下面显示的代码中不一致,因为在调用“getLatLng”方法之前,我显示了10个有效位置,但在这行代码之后,每次搜索时实际显示的点数都不同(相同的搜索条件-fyi),随机在5到10之间。非常奇怪

    有人有类似的问题吗?如果是这样,你是如何解决的?

    geocoder = new GClientGeocoder();
    geocoder.getLatLng(address, function(point) {
    if (point) {
            var icon = new GIcon();
            var marker = new GMarker(point, { icon: icon });
            GEvent.addListener(marker, 'click', function() { marker.openInfoWindowHtml(html); });
            map.addOverlay(marker);
    
    4 回复  |  直到 16 年前
        1
  •  1
  •   Saif Khan    16 年前

    我在ASP中见过这个。NET应用程序。我的问题是,在显示地址之前,我正在验证地址

    1. 我的一些地址不正确。

    2. 他们的地址验证系统只能处理客户端每次呼叫的一定数量的请求。

    最好在地理编码之前先清除地址(IMO)。

    尝试验证您的地址,并尝试限制您发送的地址数量,以测试每个请求是否连续。

    希望这能有所帮助。

        2
  •  1
  •   Michael    14 年前

    像这样试试,我一次跑就得了34分:

    function addAddress(address,runde) {
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
            //alert(address + " not found");
            if (runde<5) { // rekursiv, try adress 5 times to get
                window.setTimeout(function() {addAddress(address,runde+1);}, 1000); // wait 1 second bevor next try
                }
          } else {
            var marker_add = new GMarker(point);
            //alert(marker.getLatLng());
            leftClick(0, marker_add.getLatLng()); // function, add marker to map
          }
        }
      );
    }  
    
        3
  •  1
  •   Sujit    13 年前

    我不确定是什么 addPreCount() 做。但我认为很明显,超时应该是索引乘以实际超时常数。

    因此,假设定义的超时常数为225。传递给地理编码器包装器的超时时间为:

    var timeout = [index_of_each_xaddr] * 225;
    window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);
    
        4
  •  0
  •   Toran Billups    16 年前

    我实际上发现,导致这种不一致的不是“验证地址”代码,而是maps api不希望大量的地理编码器调用,所以我在每个请求之间添加了一个简单的225毫秒超时,这就成功了

    function preGeoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus) {
            addPreCount();
    
            //don't change this timeout as it was the lowest timeout that still worked w/ the api
            var timeout = parseInt(precount) * 225;
    
            window.setTimeout(function() { geoCodeLookup(_xaddr, _xid, _xindex, _xhtml, _xstatus); }, timeout);
        }
    
    推荐文章