如何在google map api v3中逐一设置标记? [英] how to set marker one by one in google map api v3?

查看:104
本文介绍了如何在google map api v3中逐一设置标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个谷歌地图,它将读取一组坐标并将标记逐一放在地图上。



以下是我的想法:
$ b

函数A {
for循环(
set marker
call setTimeout('A',2seconds)

}



我的想法是设置一个标记并使用setTimeout等待2秒,然后设置下一个标记。



然而,它不起作用。它会同时显示所有标记并重复更新所有标记。



我如何实现目标?
感谢您的帮助!!!!!!!!!!!!!!!

以下是我的代码:

function marker(){
var marker;
var i = 0;

while(i< locations.length){
marker = new google.maps.Marker({
position:new google.maps.LatLng(locations [i] [1 ],位置[i] [2]),
动画:google.maps.Animation.DROP,
map:map
});
i = i + 1;
var t = setTimeout(marker(),2000);
}
}
marker();


解决方案

设置第一个标记后需要返回。您还需要一个参数给A,它指定显示哪个标记。


$ b

  function marker(i) {
if(i> locations.length)return;

var marker;

marker = new google.maps.Marker({
position:new google.maps.LatLng(locations [i] [1],locations [i] [2]),
动画:google.maps.Animation.DROP,
map:map
});

var t = setTimeout(marker(+(i + 1)+),2000);
}
marker(0);


I am doing a google map which will read a set of coordinates and put the marker on the map one by one.

Below is my idea:

function A{
   for loop( 
      set marker
      call setTimeout('A',2seconds)
   )    
}

my idea is to set a marker and use setTimeout to wait 2 seconds and then set the next marker.

However, it doesn't work. it show all the markers at the same time and repeat to renew all markers.

How can i achieve my goal? Thanks for your help!!!!!!!!!!!!!!!

Here is my code:

function marker(){
    var marker;
    var i=0;

    while(i<locations.length){
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            animation: google.maps.Animation.DROP,
            map: map
            });
        i=i+1;
        var t=setTimeout("marker()",2000);
    }
}
marker();

解决方案

You need to return after setting the first marker. You also need a parameter to A which specifies which marker to show.

function marker(i){
    if (i > locations.length) return;

    var marker;

    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        animation: google.maps.Animation.DROP,
        map: map
        });

    var t=setTimeout("marker("+(i+1)+")",2000);
}
marker(0);

这篇关于如何在google map api v3中逐一设置标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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