bookmark google maps javascript uber style

0

I need to make a map on a web page with markers that move according to the user's location on the map. like the uber in the map of the uber application.

try to do this but it looks bad.

var map;
function initMap() {
  var myLatLng = app.ubicacion;
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 17,
    center: myLatLng,
    disableDefaultUI: true
  });

  setInterval(mar,250);

  function mar() {
      var image = 'img/taxi2.png'
      var marker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        title: app.username,
        icon: image
      });
      setInterval(rem, 200)
      function rem() {
        marker.setMap(null);
      }
      console.log(myLatLng.lat)
  }

}

in Spanish I create a marker and I delete it and create it again in case the location has been updated.

I would like to know if there is another way to do it?

    
asked by Wilberth Loría 27.02.2017 в 08:43
source

1 answer

0

It's actually easier than it seems. Once you have created the marker you just have to update your position as you get updated data. For this you can use the setPosition method on the bookmark.

    
answered by 27.02.2017 / 09:29
source