-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Decouple OnMyLocationChangeListener
from UserLocationView
#4700
Comments
I'm now also noticing we have 2 Location calbacks: @Override
public void onLocationChanged(Location location) {
}
@Override
public void onMyLocationChange(@Nullable Location location) {
} |
Just seeing this now as part of #5282 and wondering if we really want to set // Current Setup
// Can be done inside `MapView.getMapAsync()`
mapboxMap.setOnMyLocationChangeListener(new MapboxMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(@Nullable Location location) {
if (location != null) {
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(location))
.zoom(16)
.bearing(0)
.tilt(0)
.build());
mapboxMap.setOnMyLocationChangeListener(null);
}
}
});
// New Setup
final Context context = this; // Needs to be done outside of `MapView.getMapAsync()`
...
LocationServices.getLocationServices(context).addLocationListener(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(location))
.zoom(16)
.bearing(0)
.tilt(0)
.build());
LocationServices.getLocationServices(context).removeLocationListener(this);
}
}); |
This issue is not so much about having a method to register for location updates, it's about having 2 different interfaces that do the exactly the same thing. That said I'm not keen on reintroducing this mainly because of separation of concerns. Making this deprecated now allows us to remove location from Mapview/MapboxMap. At some point this could be migrated into a separate library or made a part of MAS. FWIW Google is doing the same where they are pointing people to use google play services instead. I'm not sure what you mean by: final Context context = this; // Needs to be done outside of `MapView.getMapAsync()` You can reference the Activity from an inner class by: LocationServices.getLocationServices(MainActivity.this).removeLocationListener(this); |
To me this is about having a simple and consistent API for developers using the MyLocation functionality in the SDK. Everything related to MyLocation is at the
I agree that it's generally not good to repeat code (aka the DRY principle), but in this case |
I think this should eventually be tackled as part of #4331, as supported by #4908 (comment), which will require a Also, I'd like to explore the idea of having MAS or the SDK to provide a default implementation based on LOST even if we move to decouple the location provider. @tobrun @bleege I suggest we remove this ticket from the |
Deprecation has been reverted in #5387 and merged into |
@tobrun 👍 thanks. |
While working on an internal app this morning I noticed that the |
Removed the remaining |
In MapView (after going through MapboxMap)
We have a method to add
OnLocationChangeListener
callback. This currently uses UserLocationView. We used to provide all the these locational changes through UserLocationView but with the introduction ofLocationServices
this is no longer needed.The text was updated successfully, but these errors were encountered: