Skip to content Skip to sidebar Skip to footer

Mapbox - Can I Use The Locationlistener Without Mapbox Map

I know the way to use locationListener and triggering the GPS is done like that: mapboxMap.setMyLocationEnabled(true); I want to open the locationListener at app start, but I don'

Solution 1:

You can use an instance of LocationEngine to acquire location updates without showing the map.

finalLocationEnginelocationEngine=newLostLocationEngine(this);
locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY);
locationEngine.addLocationEngineListener(newLocationEngineListener() {
  @OverridepublicvoidonConnected() {
    locationEngine.requestLocationUpdates();
  }

  @OverridepublicvoidonLocationChanged(Location location) {

  }
});
locationEngine.activate();

Make sure that once you finish getting the location information needed or your activity gets destroyed you remove all listeners, stop requesting updates and deactivate the engine.

Solution 2:

The answer is no! You cannot do it and I recommend you should not do it as it will increase your apk size a lot. If you just need the location listener, there're a lot of libraries which can do it for you as: Smart Location Library:

SmartLocation.with(context).location()
.start(new OnLocationUpdatedListener() { ... });

Post a Comment for "Mapbox - Can I Use The Locationlistener Without Mapbox Map"