Google地图上的自动刷新标记 [英] auto refresh marker on google map
本文介绍了Google地图上的自动刷新标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在地图上间隔一段时间后移动标记..
我具有以下相同的代码...但是我想使用某种类型的纬度和经度点数组来完成此操作,因此标记在地图上的许多点上移动...
这是我的代码...谢谢您的帮助!!!!
i want to move marker after some interval on map..
i have following code for the same...but i want to do it with some type of array of latitude and longitude points so marker is move on many points on map...
here is my code...thank u for help !!!!
var map;
function initialize()
{
var latlng = new google.maps.LatLng(21.16536,72.79387);
var NewLatLng = new google.maps.LatLng(20.371237, 72.90634);
var NewLatLng1 = new google.maps.LatLng(19.9974533, 73.78980230);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker
(
{
position: new google.maps.LatLng(21.1673643, 72.7851802),
map: map,
title: 'Click me'
}
);
setInterval(function() { marker.setPosition(NewLatLng);}, 2000);
setInterval(function() { marker.setPosition(NewLatLng1);}, 7000);
var infowindow = new google.maps.InfoWindow({
content: 'Location info:<br/>SVNIT Post Office, Dumas Rd, Surat<br/>LatLng:<br/>21.1673643, 72.7851802'
});
google.maps.event.addListener(marker, 'click', function ()
{
infowindow.open(map, marker);
setTimeout(function(){infowindow.close();}, '5000');
});
}
window.onload = initialize;
推荐答案
尝试一下
< script src ="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type ="text/javascript"></script>
< script type ="text/javascript" src ="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
< script type ="text/javascript">
var location = [
[''19 .0018014'',''72.914170300''],[''18.4915595'',''73.886065199''],[''17.5272371'',''75.957780299''],[''19.0787678'',' '75 .752507899''],[''19.9971895'',''73.916395800''],[''19.0150482'',''72.855971599'']
];
var map;
var NewLatLng = [];
var markers = [];
var标记;
函数initialize()
{
var latlng = new google.maps.LatLng(21.16536,72.79387);
var myOptions = {
缩放:5,
中心:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"),myOptions);
marker =新的google.maps.Marker
(
{
位置:新google.maps.LatLng(21.1673643,72.7851802),
地图:地图,
标题:点击我"
}
);
markers.push(marker);
Try this
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">
var locations=[
[''19.0018014'',''72.914170300''],[''18.4915595'',''73.886065199''],[''17.5272371'',''75.957780299''],[''19.0787678'',''75.752507899''],[''19.9971895'',''73.916395800''],[''19.0150482'',''72.855971599'']
];
var map;
var NewLatLng=[];
var markers=[];
var marker ;
function initialize()
{
var latlng = new google.maps.LatLng(21.16536,72.79387);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), myOptions);
marker = new google.maps.Marker
(
{
position: new google.maps.LatLng(21.1673643, 72.7851802),
map: map,
title: ''Click me''
}
);
markers.push(marker);
.each(位置,功能(i,项目){
NewLatLng.push(new google.maps.LatLng(item [0],item [1]));
});
var infowindow = new google.maps.InfoWindow({
内容:``位置信息:
SVNIT邮局,杜马斯路,苏拉特
LatLng:
21.1673643,72.7851802''
});
google.maps.event.addListener(marker,``click'',function()
{
infowindow.open(地图,标记);
setTimeout(function(){infowindow.close();},``5000'');
});
.each(locations, function (i, item) {
NewLatLng.push(new google.maps.LatLng(item[0], item[1]));
});
var infowindow = new google.maps.InfoWindow({
content: ''Location info:
SVNIT Post Office, Dumas Rd, Surat
LatLng:
21.1673643, 72.7851802''
});
google.maps.event.addListener(marker, ''click'', function ()
{
infowindow.open(map, marker);
setTimeout(function(){infowindow.close();}, ''5000'');
});
.each(NewLatLng,function(i,item){
setTimeout(function(){
marker.setPosition(item);
markers.push(marker);
},i * 1000);
});
}
window.onload =初始化;
</script>
.each(NewLatLng, function (i, item) {
setTimeout(function(){
marker.setPosition(item);
markers.push(marker);
}, i*1000);
});
}
window.onload = initialize;
</script>
这篇关于Google地图上的自动刷新标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文