Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set the new position of marker with Gmaps.js?

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?

like image 258
Brotheryura Avatar asked Dec 11 '25 21:12

Brotheryura


2 Answers

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.

like image 177
Dr.Molle Avatar answered Dec 13 '25 09:12

Dr.Molle


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);
like image 26
Kappa Avatar answered Dec 13 '25 09:12

Kappa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!