S
S
serNevajno2017-06-16 15:35:51
JavaScript
serNevajno, 2017-06-16 15:35:51

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

1 answer(s)
I
Immortal_pony, 2017-06-16
@serNevajno

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 question

Ask a Question

731 491 924 answers to any question