Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

[android] Add a way to use a custom location source#8710

Merged
Guardiola31337 merged 2 commits into
masterfrom
pg-8668-location-source
Apr 20, 2017
Merged

[android] Add a way to use a custom location source#8710
Guardiola31337 merged 2 commits into
masterfrom
pg-8668-location-source

Conversation

@Guardiola31337
Copy link
Copy Markdown
Contributor

Fixes #8668

👀 @tobrun

@Guardiola31337 Guardiola31337 added Android Mapbox Maps SDK for Android feature Google Maps parity For feature parity with the Google Maps SDK for Android or iOS localization Human language support and internationalization labels Apr 11, 2017
@Guardiola31337 Guardiola31337 force-pushed the pg-8668-location-source branch from 86488cd to d3faa66 Compare April 11, 2017 16:48
Copy link
Copy Markdown
Member

@tobrun tobrun left a 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

* Set to null to use the default {@link LocationSource}
* location source.
*/
@UiThread
Copy link
Copy Markdown
Member

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.

myLocationView.setEnabled(locationEnabled);
}

void setLocationSource(LocationEngine locationSource) {
Copy link
Copy Markdown
Member

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().


private LatLng latLng;
private Location location;
private LocationEngine locationSource;
Copy link
Copy Markdown
Member

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.

contentPaddingY = (padding[1] - padding[3]) / 2;
}

public void setLocationSource(LocationEngine locationSource) {
Copy link
Copy Markdown
Member

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;
Copy link
Copy Markdown
Member

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.

@Guardiola31337 Guardiola31337 force-pushed the pg-8668-location-source branch 2 times, most recently from 3058fa6 to 3ac6ad6 Compare April 13, 2017 14:57
@tobrun tobrun force-pushed the pg-8668-location-source branch from 3ac6ad6 to 827da47 Compare April 13, 2017 15:23
@Guardiola31337 Guardiola31337 force-pushed the pg-8668-location-source branch from 827da47 to 652bde0 Compare April 13, 2017 16:07
@Override
public void onClick(View view) {
if (mapboxMap != null) {
mapboxMap.setLocationSource(locationServices);
Copy link
Copy Markdown
Member

@zugaldia zugaldia Apr 18, 2017

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().

Copy link
Copy Markdown
Contributor Author

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?

Copy link
Copy Markdown
Member

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);
}

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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
}

@Guardiola31337 Guardiola31337 merged commit c6be40b into master Apr 20, 2017
@Guardiola31337 Guardiola31337 deleted the pg-8668-location-source branch April 20, 2017 18:10
@tobrun tobrun mentioned this pull request May 2, 2017
12 tasks
@tobrun tobrun added this to the android-v5.1.0 milestone May 4, 2017
@Ehekatl
Copy link
Copy Markdown

Ehekatl commented May 15, 2017

I manage to use this to fix issue #8639 #8848
However after I change location source to my own location engine in background service, the map view lost the ability to update user location gradually and start jumping to the new position immediately on location change.
Is there any way to solve it?

@zugaldia
Copy link
Copy Markdown
Member

@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 CustomLocationEngineActivity

@tobrun tobrun mentioned this pull request Jun 9, 2017
12 tasks
@tobrun tobrun mentioned this pull request Jun 21, 2017
11 tasks
@tobrun tobrun mentioned this pull request Jun 30, 2017
16 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android feature Google Maps parity For feature parity with the Google Maps SDK for Android or iOS localization Human language support and internationalization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants