title: Leaflet How To Update User Position Marker Real Time
body: <p>I am trying to update user position in leaflet.Like when user walks with phone their location marker will move too based on location data just like google maps.</p>
  
  <p>Right now im just putting a marker on their initial position</p>
  
  <pre><code>    this.map.locate({
    setView: true,
    maxZoom: 120
  }).on("locationfound", e =&gt; {
  
    leaflet.marker([e.latitude, e.longitude]).bindPopup("YOU ARE HERE!").addTo(this.map);
  
  
  
    console.log("lokasyon bulundu");
  }).on("locationerror", error =&gt; {
  
    console.log("lokasyon bulunamadi");
  });
  </code></pre>
  
  <p>Tried update() method but couldnt make it work.i guess i should take user location data every second and if it different then draw new marker and remove old  one ? is this a efficient way ? </p>
  
  <p>thanks 
  edit this is what i tried based on answer. its not working.im pulling data from db and based on that determining custom marker </p>
  
  <pre><code>this.map.locate({
      setView: true,
      maxZoom: 120,
      watch:true,
      enableHighAccuracy:true
    }).on("locationfound", e =&gt; {
        if (!usermarker) {
  
          if(this.profileData.avatar == "https://i.hizliresim.com/zJJ239.png"){
            usermarker = new L.marker(e.latlng,{icon : ayi}).addTo(this.map);
          }else if(this.profileData.avatar == "https://i.hizliresim.com/mJJrkP.png"){
            usermarker = new L.marker(e.latlng,{icon : ironman}).addTo(this.map);
          }else if(this.profileData.avatar == "https://i.hizliresim.com/vJJQpp.png"){
            usermarker = new L.marker(e.latlng,{icon : dino}).addTo(this.map);
          }else if(this.profileData.avatar == "https://i.hizliresim.com/zJJ2B9.png"){
            usermarker = new L.marker(e.latlng,{icon : petyr}).addTo(this.map);
          }
        } else if(this.profileData.avatar == "https://i.hizliresim.com/zJJ239.png") {
            usermarker.setLatLng(e.latlng);
        }
    }).on("locationerror", error =&gt; {
        if (usermarker) {
            map.removeLayer(usermarker);
            usermarker = undefined;
        }
    });
  </code></pre>