最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can i set the new position of marker with Gmaps.js? - Stack Overflow

programmeradmin2浏览0评论

With GMaps.js i can add markers easy way:

map.addMarker({  
              lat: -12.043333,
              lng: -77.028333
              });

After create that marker, i want to set him a new position after some time. For example my next code:

setInterval(function() {
     setNewPosition();
}, 5000);

setNewPosition(){   
   map.removeMarkers();

   map.addMarker({  
                  lat: -13.043333,
                  lng: -77.028333
                  });
}

But i don`t want all time a removed marker, i want only set him a new position. That is the really possible? I know in google map it solved with google.maps.LatLng() and .setPosition(), but how in Gmaps.js they used?

With GMaps.js i can add markers easy way:

map.addMarker({  
              lat: -12.043333,
              lng: -77.028333
              });

After create that marker, i want to set him a new position after some time. For example my next code:

setInterval(function() {
     setNewPosition();
}, 5000);

setNewPosition(){   
   map.removeMarkers();

   map.addMarker({  
                  lat: -13.043333,
                  lng: -77.028333
                  });
}

But i don`t want all time a removed marker, i want only set him a new position. That is the really possible? I know in google map it solved with google.maps.LatLng() and .setPosition(), but how in Gmaps.js they used?

Share Improve this question edited Sep 4, 2013 at 10:23 Brotheryura asked Sep 4, 2013 at 8:36 BrotheryuraBrotheryura 1,18814 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

As far as I know there is no special method to set the position.

addMarker() returns a native google.maps.Marker, so you may store this marker in a variable and call setPosition() later.

addMarker() return a google.maps.Marker, so call setPosition() function with new google.maps.LatLng

var latlng = new google.maps.LatLng(45.667, 12.239);
marker.setPosition(latlng);
发布评论

评论列表(0)

  1. 暂无评论