如何更新谷歌标记的位置 [英] how to update position of google marker

查看:87
本文介绍了如何更新谷歌标记的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我需要每5秒更新一次Google标记位置

我有这个JavaScript代码用于在页面加载时绘制Google标记。



我希望能够每5秒更改一次标记的位置。



这是我的代码:

 函数初始化(){
var myOptions = {
zoom:4,
center:new google.maps.LatLng (-25.363882,131.044922),
mapTypeId:google.maps.MapTypeId.ROADMAP
};


var map = new google.maps.Map(document.getElementById('map_canvas'),
myOptions);

var image = new google.maps.MarkerImage(images / truck3.png,
google.maps.Size(32.0,37.0),
google.maps .Point(0,0),
new google.maps.Point(16.0,18.0)
);
var shadow = new google.maps.MarkerImage(images / shadow-truck3.png,
new google.maps.Size(51.0,37.0),
google.maps.Point (0,0),
new google.maps.Point(16.0,18.0)
);

var marker = new google.maps.Marker({
position:map.getCenter(),
map:map,
icon:image,
shadow:shadow,
title:'Click to zoom'
});

google.maps.event.addDomListener(window,'load',initialize);



还有一件事,当多出一个标记时,我怎么可以放多个点。
我知道这对你来说可能是微不足道的,但我对此完全陌生。



编辑:



我很抱歉,但这谷歌让我困惑。所以我想要做的是接下来。当页面加载我想检索和阵列的最后职位,每个职位将有他们的ID,所以PHP数组将会像数组[拉] [Lng] [ID],之后,我想把每个的位置,并把它放在屏幕的中心。当用户点击一个标记时,它会自动缩放,并开始每秒钟将标记位置放在中心位置。并且我需要一个用于该特定标记的ID。



这是一个类似的问题,如果一些java大师可以将这些结合起来以得到我需要的



在相似的问题上链接

解决方案

将这个javascript函数添加到您的代码中,

  $(function(){
setTimeout(function(){$('#map_canvas')。load(ini​​tialize);},50000);
})


Hi all I need to update google markers position every 5sec

I have this javascript code for drawing a google markers when page loads.

I want to be able to change position of the markers every 5 sec.

Here is my code:

function initialize() {
  var myOptions = {
    zoom: 4,
    center: new google.maps.LatLng(-25.363882, 131.044922),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };


  var map = new google.maps.Map(document.getElementById('map_canvas'),
      myOptions);

  var image = new google.maps.MarkerImage("images/truck3.png",
        new google.maps.Size(32.0, 37.0),
        new google.maps.Point(0, 0),
        new google.maps.Point(16.0, 18.0)
    );
  var shadow = new google.maps.MarkerImage("images/shadow-truck3.png",
        new google.maps.Size(51.0, 37.0),
        new google.maps.Point(0, 0),
        new google.maps.Point(16.0, 18.0)
    );

  var marker = new google.maps.Marker({
    position: map.getCenter(),
    map: map,
    icon: image,
    shadow: shadow,
    title: 'Click to zoom'
  });

google.maps.event.addDomListener(window, 'load', initialize);

One more thing how can I put multiple points when showing more then one marker. I know this is probably trivial for you but I am totally new at this.

EDIT:

I am sorry but this google got me tottaly confused. So What I want to do is next. When page loads I want to retrieve and array of last positions and each of that positions will have their id so an php array would be like array[Lat][Lng][id], after that I would like to put and marker on each of that position and put it in the center of the screen. When user clicks on one marker it will automatically zoom and start putting the marker position in the center every second. And I need an id for that certain marker.

This is a similar question, it would be nice if some java guru can combine me those to to get what I need

LINK ON THE SIMILAR QUESTION

解决方案

Add this javascript function to your code ,

 $(function () {
        setTimeout(function () { $('#map_canvas').load(initialize); }, 50000);
    })

这篇关于如何更新谷歌标记的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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