Search code examples
gpsgeolocationleaflet

Obtaining altitude and heading in leaflet


Im using leaflet for my mobile app. I can gain access to e.latlng and e.accuracy with no problem but e.speed and e.heading just return UNDEFINED

$scope.makeFit = function() {
        leafletData.getMap().then(function(map) {
        map.locate({setView: true, maxZoom: 16, watch:true,enableHighAccuracy: true});
        map.on('locationfound', onLocationFound);
         punto = L.circleMarker([35.80048816577000, 9.634765625], {color: '#136AEC', fillColor: '#2A93EE',fillOpacity: 0.7, weight: 2,opacity: 0.9, radius: 4}).addTo(map);
         function onLocationFound(e) {
       var radius = e.accuracy / 2;
       punto.setLatLng(e.latlng);

      alert(e.altitude);


  }

        });
      };

Solution

  • This is an implementation detail of your specific device - some phones or computers support heading and speed, some don't. It's not something that Leaflet can guarantee, so Leaflet just passes what your device offers on to you in the event.