[android] Add a way to use a custom location source#8710
Conversation
86488cd to
d3faa66
Compare
tobrun
left a comment
There was a problem hiding this comment.
Looking great, could we add a test around this? maybe adding a mock example in the test app (could be integrated in an existing activity)? Changelog entry would be appreciated
| * Set to null to use the default {@link LocationSource} | ||
| * location source. | ||
| */ | ||
| @UiThread |
There was a problem hiding this comment.
Let's call this setLocationEngine.
| myLocationView.setEnabled(locationEnabled); | ||
| } | ||
|
|
||
| void setLocationSource(LocationEngine locationSource) { |
There was a problem hiding this comment.
Similarly, let's call it setLocationEngine().
|
|
||
| private LatLng latLng; | ||
| private Location location; | ||
| private LocationEngine locationSource; |
There was a problem hiding this comment.
I'd rather call it locationEngine even if LocationSource is our default implementation.
| contentPaddingY = (padding[1] - padding[3]) / 2; | ||
| } | ||
|
|
||
| public void setLocationSource(LocationEngine locationSource) { |
| private static class GpsLocationListener implements LocationEngineListener { | ||
|
|
||
| private WeakReference<MyLocationView> userLocationView; | ||
| private WeakReference<LocationEngine> locationSource; |
There was a problem hiding this comment.
Similarly, let's call the variable locationEngine.
3058fa6 to
3ac6ad6
Compare
3ac6ad6 to
827da47
Compare
827da47 to
652bde0
Compare
| @Override | ||
| public void onClick(View view) { | ||
| if (mapboxMap != null) { | ||
| mapboxMap.setLocationSource(locationServices); |
There was a problem hiding this comment.
@Guardiola31337 Do we need to set a location source every time the FAB is clicked? Wouldn't we need to set it just once if it hasn't been set before? Also, I don't see a getLocationSource() method to check that, or alternatively a isCustomLocationSourceSet().
There was a problem hiding this comment.
@zugaldia you're right, setting it once would be enough.
I don't see the necessity of having getLocationSource or isCustomLocationSourceSet methods, because if it isn't set we use LocationSource (default). What would be the use case?
There was a problem hiding this comment.
What would be the use case?
@Guardiola31337 Check if it's been set or not. For example, this activity could've been written like:
if (mapboxMap.getLocationSource() == null) {
mapboxMap.setLocationSource(locationServices);
}
There was a problem hiding this comment.
@zugaldia there is always a location source. It can't be null. So it doesn't make sense.
There was a problem hiding this comment.
@Guardiola31337 Alternatively:
if (mapboxMap.getLocationSource() instanceof MyCustomLocationSource) {
// Safe cast
}
652bde0 to
4837b17
Compare
|
@Ehekatl thanks for the report. I'd like to explore the root cause for this misbehavior. Could you open a new ticket and, if possible, share the code for your custom location engine? For reference, we provide a sample implementation of a custom location engine on |
Fixes #8668
👀 @tobrun