Skip to content

Commit

Permalink
Fixes Location request hang if location service is unvailable or perm…
Browse files Browse the repository at this point in the history
…issions are denied

see maplibre#508
  • Loading branch information
stevehayles committed Jan 18, 2025
1 parent b5919d3 commit 3508763
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,10 @@ public void onError(@NonNull String message) {
case "locationComponent#getLastLocation":
{
Log.e(TAG, "location component: getLastLocation");
if (this.myLocationEnabled && locationComponent != null && locationEngine != null) {
if (this.myLocationEnabled
&& locationComponent != null
&& locationComponent.isLocationComponentActivated()
&& locationComponent.getLocationEngine() != null) { {
Map<String, Object> reply = new HashMap<>();
locationEngine.getLastLocation(
new LocationEngineCallback<LocationEngineResult>() {
Expand All @@ -1155,6 +1158,11 @@ public void onFailure(@NonNull Exception exception) {
result.error("", "", null); // ???
}
});
} else {
result.error(
"LOCATION DISABLED",
"Location is disabled or location component is unavailable",
null);
}
break;
}
Expand Down Expand Up @@ -1863,7 +1871,7 @@ public void setPuckSize(Double puckSize) {
}

private void updateMyLocationEnabled() {
if (this.locationComponent == null && myLocationEnabled) {
if (this.locationComponent == null && mapboxMap.getStyle() != null && myLocationEnabled) {
enableLocationComponent(mapboxMap.getStyle());
}

Expand All @@ -1881,6 +1889,7 @@ private void updateMyLocationEnabled() {
private void startListeningForLocationUpdates() {
if (locationEngineCallback == null
&& locationComponent != null
&& locationComponent.isLocationComponentActivated()
&& locationComponent.getLocationEngine() != null) {
locationEngineCallback =
new LocationEngineCallback<LocationEngineResult>() {
Expand All @@ -1902,6 +1911,7 @@ public void onFailure(@NonNull Exception exception) {}
private void stopListeningForLocationUpdates() {
if (locationEngineCallback != null
&& locationComponent != null
&& locationComponent.isLocationComponentActivated()
&& locationComponent.getLocationEngine() != null) {
locationComponent.getLocationEngine().removeLocationUpdates(locationEngineCallback);
locationEngineCallback = null;
Expand Down

0 comments on commit 3508763

Please sign in to comment.