-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[android] Add a way to use a custom location source #8710
Conversation
86488cd
to
d3faa66
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
* location source. | ||
*/ | ||
@UiThread | ||
public void setLocationSource(@Nullable LocationEngine locationSource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call this setLocationEngine
.
@@ -362,6 +365,11 @@ void setMyLocationEnabled(boolean locationEnabled) { | |||
myLocationView.setEnabled(locationEnabled); | |||
} | |||
|
|||
void setLocationSource(LocationEngine locationSource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, let's call it setLocationEngine().
@@ -58,6 +58,7 @@ | |||
|
|||
private LatLng latLng; | |||
private Location location; | |||
private LocationEngine locationSource; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather call it locationEngine
even if LocationSource
is our default implementation.
@@ -561,22 +563,29 @@ public void setContentPadding(int[] padding) { | |||
contentPaddingY = (padding[1] - padding[3]) / 2; | |||
} | |||
|
|||
public void setLocationSource(LocationEngine locationSource) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: setLocationEngine().
private static class GpsLocationListener implements LocationEngineListener { | ||
|
||
private WeakReference<MyLocationView> userLocationView; | ||
private WeakReference<LocationEngine> locationSource; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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