Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the position of marker from a javascript function?

I have to change the position of a marker on Google map from a javascript function. How can I achieve that?

like image 751
Saurabh Avatar asked Apr 28 '11 11:04

Saurabh


People also ask

How do I change marker positions?

First off you must store the marker in an array when you create it so you can have access to it afterwards. Then change the position with marker. setPosition() as solidrevolution mentioned.

How do you move a marker in maps?

Setting a marker's draggable property to true allows the user to change the position of the marker. Use a long press to activate the ability to move the marker.

How do you move a marker smoothly?

There is a method makeMarker() you just need to call from onMapReady() method . There is two method rotateMarker() and moveVechile() to rotate and move marker. Hope this will help you.

How do I move a marker in Google Maps API?

Just try to create the marker and set the draggable property to true . The code will be something as follows: Marker = new google.


2 Answers

You can use setPosition function of the marker class

function changeMarkerPosition(marker) {     var latlng = new google.maps.LatLng(-24.397, 140.644);     marker.setPosition(latlng); } 
like image 121
solidrevolution Avatar answered Sep 17 '22 05:09

solidrevolution


First off you must store the marker in an array when you create it so you can have access to it afterwards.
Then change the position with marker.setPosition() as solidrevolution mentioned.

like image 33
Argiropoulos Stavros Avatar answered Sep 21 '22 05:09

Argiropoulos Stavros