Javascript谷歌地图,只显示10个标记中的100个。是否有限制? [英] Javascript Google maps, displays only 10 markers out of 100. Is there a limit?

查看:90
本文介绍了Javascript谷歌地图,只显示10个标记中的100个。是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是链接: http://alchemist3d.com/maptest.html



另外我在循环中使用geocoder来获取地址数组的坐标,这里是代码:

函数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,标题:f 2},
{location :Gladiola卫星Cuernavaca莫雷洛斯墨西哥,身体: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);


函数codeLocations(list,map){
for(var i = 0; i< list.length; i ++){
// console。日志(循环+列表[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));



函数createGeocodeCallback(item,map){
//console.log(\"Generator geocode callback for+ item.location);
返回函数(结果,状态){
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);



$ b函数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);
});
}

函数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);
返回新的google.maps.LatLngBounds(西南,东北);
}


解决方案

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



如果你很勇敢,你可以尝试:

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

我不知道为什么每个人都使用200毫秒,也许来自试验和错误?您可以尝试150或100次。但是,在100毫秒时,您需要10秒才能加载100个标记。我读到的另一个想法是批量查询。 Geocode十,等等,然后再等十。



另一个可以尝试的函数是 sleep


$ b $ pre $ function sleep(milliSeconds){
var startTime = new Date()。getTime(); (new Date()。getTime()< startTime + milliSeconds);
while
}


Here is the link: http://alchemist3d.com/maptest.html

Also I'm using geocoder in a loop to get the coordinates of an array of addresses, here is the code:

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);
}

解决方案

Yes, there is a rate limit, which isn't too well documented. 9-10 requests per second? If you check the error status, it's called OVER_QUERY_LIMIT. With 100 markers, I don't think the common waiting technique will do you much good, because you have a lot of markers. It's best to geocode once, save the LatLngs and use them.

If you're brave, you can try:

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

I don't know why everyone uses 200 ms, maybe from trial and error? You can try 150, or 100. Still, at 100 ms it will take you 10 seconds to load 100 markers. Another idea I read about is to query in batches. Geocode ten, wait, then another ten.

An alternate function you can try is sleep.

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

这篇关于Javascript谷歌地图,只显示10个标记中的100个。是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆