【问题标题】:Javascript Google maps, displays only 10 markers out of 100. Is there a limit?Javascript Google 地图,仅显示 100 个标记中的 10 个。有限制吗?
【发布时间】:2012-06-01 12:48:07
【问题描述】:

这里是链接:http://alchemist3d.com/maptest.html

我还在循环中使用地理编码器来获取地址数组的坐标,代码如下:

function initialize() {
  var list = [
  {location:"residencial punta del sol casa 6  temixco Morelos Mexico",body : " 1", title : "m 1"},
  {location:"prol. harris num. 23 ampl. bugambilias jiutepec Morelos Mexico",body : "ampl. bugambilias 2", title : "f 2"},
  {location:"Gladiola Satelite Cuernavaca Morelos Mexico",body:"Montes de Oca"}
  ];
  var latlng = new google.maps.LatLng(18.92009,-99.20611);
  var myOptions = {
    zoom: 12,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  //map.fitBounds(getBounds());
  codeLocations(list, map);
}

function codeLocations(list, map) {
  for (var i = 0; i < list.length; i++) {
    //console.log("Looping " + list[i].location);
    var geocoder = new google.maps.Geocoder();
    var geoOptions = {
      address: list[i].location,
      bounds: getBounds(),
      region: "NO"
    };
    geocoder.geocode(geoOptions, createGeocodeCallback(list[i], map));
  }
}

function createGeocodeCallback(item, map) {
  //console.log("Generating geocode callback for " + item.location);
  return function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      //console.log("Geocoding " + item.location + " OK");
      addMarker(map, item, results[0].geometry.location);
    } else {
      //console.log("Geocode failed " + status);
    }
  }
}

function addMarker(map, item, location) {
  //console.log("Setting marker for " + item.location + " (location: " + location + ")");
  var marker = new google.maps.Marker({ map : map, position : location});
  marker.setTitle(item.title);
  var infowindow = new google.maps.InfoWindow( {
    content : item.body,
    size : new google.maps.Size(100, 300)
  });
  new google.maps.event.addListener(marker, "click", function() {
    infowindow.open(map, marker);
  });
}

function getBounds() {
  var myOptions = {
    zoom: 23,
    center: new google.maps.LatLng(-33.9, 151.2),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  var southwest = new google.maps.LatLng(17.920,-100.206);
  var northeast =new google.maps.LatLng(19.920,-104.206);
  return new google.maps.LatLngBounds(southwest, northeast);
}

【问题讨论】:

    标签: javascript google-maps-api-3 geocoding


    【解决方案1】:

    是的,有一个速率限制,没有很好的记录。每秒 9-10 个请求?如果您检查错误状态,则称为 OVER_QUERY_LIMIT。有 100 个标记,我认为常见的等待技术不会对你有多大好处,因为你有很多标记。最好进行一次地理编码,保存 LatLng 并使用它们。

    如果你胆子大,可以试试:

    setTimeout(function(){
      geocoder.geocode(geoOptions, createGeocodeCallback(list[i], map));
    }, 200*i);
    

    我不知道为什么每个人都使用 200 毫秒,也许是因为反复试验?您可以尝试 150 或 100。不过,在 100 毫秒时,加载 100 个标记需要 10 秒。我读到的另一个想法是批量查询。地理编码十个,等待,然后再十个。

    您可以尝试的另一个功能是sleep

    function sleep(milliSeconds) {
      var startTime = new Date().getTime();
      while (new Date().getTime() < startTime + milliSeconds);
    }
    

    【讨论】:

    • 我尝试过使用 sleep(10000);但我仍然只得到 11 个标记。
    【解决方案2】:

    Lilina 对速率限制的看法是正确的,但可以根据您是否违反限制来改变速率。 200 毫秒可能一直没问题,但另请参阅this linked question,其中有一个变化速率的示例,它开始比这更快(实际上只减慢到 150 毫秒左右)。

    那里叙述的问题与您的完全相同相同。

    Google Map V3 : Only some markers are displayed

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-21
      • 2017-12-09
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多