Answer the question
In order to leave comments, you need to log in
How to implement dynamic marker on google maps?
Hello uv. community. Help me to understand. I want to implement a dynamic change of the marker position after a certain amount of time without overloading the map itself. Here is the map drawing code:
function initCrew(lat, lng) {
var lat_point = +lat;
var lng_point = +lng;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 8,
center: {lat: lat_point, lng: lng_point}
});
var image = 'http://www.iconcraze.com/wp-content/uploads/2016/11/ICONCRAZE-COM-Police-Car-Icon-PNG.png';
var beachMarker = new google.maps.Marker({
position: {lat: lat_point, lng: lng_point},
map: map
});
}
Answer the question
In order to leave comments, you need to log in
var beachMarker = null;
var changeTimeout = 5000;
function initCrew(lat, lng) {
...
beachMarker = new google.maps.Marker({ // without "var"
...
}
setTimeout(function() {
beachMarker.setPosition(new google.maps.LatLng(newLat, newLng));
}, changeTimeout);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question