Reputation: 1
I make an Android app with mapbox based on the proposed example of the official documentation.
When GPS is desable or when GPS signal is weak, showing a user's location doesn't work.
however the app using well the HIGT_ACCURACY priority and data mobile is enable.
Any idea ?
thanks
edit*
private void enableLocationComponent() {
if (PermissionsManager.areLocationPermissionsGranted(this)) {
LocationComponentOptions options = LocationComponentOptions.builder(this)
.trackingGesturesManagement(true)
.accuracyAlpha(0)
.maxZoom(getResources().getInteger(R.integer.zoom_max))
.minZoom(getResources().getInteger(R.integer.zoom_min))
.accuracyColor(ContextCompat.getColor(this, R.color.primary))
.build();
mapboxMap.getLocationComponent().activateLocationComponent(this, options);
mapboxMap.getLocationComponent().setLocationComponentEnabled(true);
mapboxMap.getLocationComponent().setCameraMode(CameraMode.TRACKING_COMPASS);
mapboxMap.getLocationComponent().setRenderMode(RenderMode.COMPASS);
mapboxMap.getLocationComponent().getLocationEngine().setPriority(LocationEnginePriority.HIGH_ACCURACY);
mapboxMap.getLocationComponent().getLocationEngine().addLocationEngineListener(this);
} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}
location work perfectly fine if GPS is enable. location doesn't appear at all if GPS is diseable.
Upvotes: 0
Views: 710
Reputation: 1764
If I understand your post correctly, the issue is that there's no location shown when GPS is disabled on app startup?
The ticket you've linked in your comment is a bit dated so I wouldn't reference any of the code that's posted there, but the solution is certainly still valid.
Instead of shipping a custom LocationEngine
the SDK retrieves the best one it could find on the device. More detail on this here.
You haven't shared this in your code snippet, but the best way to retrieve the most recent location update is to override the onSuccess
method of the LocationEngineCallback
. Like so:
@Override
public void onSuccess(LocationEngineResult result) {
MainActivity activity = activityWeakReference.get();
if (activity != null) {
Location location = result.getLastLocation();
if (location == null) {
return;
}
// Pass the new location to the Maps SDK's LocationComponent
if (activity.mapboxMap != null && result.getLastLocation() != null) {
activity.mapboxMap.getLocationComponent().forceLocationUpdate(result.getLastLocation());
}
}
}
(Note that I snagged the above code from the documentation.)
If the device you're running your app on has no recent location information - which can happen if you've disabled GPS for an extended period of time - there will be nothing retrieved by the LocationEngine and the LocationComponent will have nothing to display.
Several custom LocationEngines, Google's being one of the most common, use additional signals to confirm a device's current location (e.g. WiFi). As a result, even if GPS is disabled, the probability of the engine returning a null
value is dramatically lower.
⚠️ Disclaimer: I currently work for Mapbox ⚠️
Upvotes: 1