Mapbox GeoTrigger disable "Location turn off"

Viewed 24

I'm using the code below to activate Geolocation on Mapbox in my PWA but when it enters the background sometimes on resume the Geolocation has timed out I can fix it by calling it geolocate.trigger(); but on 3 time of doing it the location marker disappears on the map so i thought is there a way to turn it on again instantly if it gets turned off? Or at least turn off the user location on mapbox and then recall it on resume?

I'm using Capacitor from Ionic and can therefore check for resuming.

     const geolocate = new mapboxgl.GeolocateControl({
     fitBoundsOptions: {
        zoom: 18,
     },
     positionOptions: {
     enableHighAccuracy: true
     },
     trackUserLocation: true,
     
     showUserHeading: true
    
     });
     
    
     
     
     map.addControl(geolocate);
   
        
      map.on('load', function () {
         
         
         
          geolocate.trigger();
      });
      /// CHECKING FOR RESUME
      document.addEventListener("resume", onResume, false);
      function onResume() {
          geolocate.trigger();
      }



0 Answers
Related