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

Implement Responsive User Location Tracking Mode #2049

Closed
bleege opened this issue Aug 12, 2015 · 80 comments
Closed

Implement Responsive User Location Tracking Mode #2049

bleege opened this issue Aug 12, 2015 · 80 comments
Assignees
Labels
Android Mapbox Maps SDK for Android

Comments

@bleege
Copy link
Contributor

bleege commented Aug 12, 2015

The User Location tracking mode (None, Follow, Bearing) was disabled in #1856 as the User Location dot was being updated on the main UI thread. The core logic is there, but it needs to be implemented in a more efficient way so that the UI remains responsive.

/cc @erf

@bleege bleege added the Android Mapbox Maps SDK for Android label Aug 12, 2015
@bleege bleege added this to the Android b1 milestone Aug 12, 2015
@erf
Copy link
Contributor

erf commented Aug 12, 2015

Could it be added as an annotation?

@ljbade
Copy link
Contributor

ljbade commented Aug 13, 2015

@bleege Is the issue that there is too many events?

@erf
Copy link
Contributor

erf commented Aug 13, 2015

i made a lowpass filter in #1968 which could be used

@erf
Copy link
Contributor

erf commented Aug 13, 2015

in addition to some minimal time / angle diff

@erf
Copy link
Contributor

erf commented Aug 13, 2015

I think you should move out the setDirection call from updateMap to the onCompassChange event.

@bleege
Copy link
Contributor Author

bleege commented Aug 13, 2015

@bleege Is the issue that there is too many events?

Yes.

@ljbade
Copy link
Contributor

ljbade commented Aug 13, 2015

@bleege How does iOS handle that?

This was referenced Aug 14, 2015
@1ec5
Copy link
Contributor

1ec5 commented Aug 14, 2015

@ljbade, on iOS, MGLMapView doesn’t do anything special. But it seems that Core Location is doing a better job of coalescing location updates than what we’re using on Android: #1676.

@bleege
Copy link
Contributor Author

bleege commented Aug 14, 2015

But it seems that Core Location is doing a better job of coalescing location updates than what we’re using on Android

Exactly. We need to put a regulator / distance filter on updates to location or specifically that a certain amount of distance / time needs to elapse before updating the dot on the map.

@ljbade
Copy link
Contributor

ljbade commented Aug 15, 2015

@bleege I recall the LOST framework has this ability to filter (certainly Google Play services do).

We still need to work in @erf's compass filter for that data.

@ljbade
Copy link
Contributor

ljbade commented Aug 15, 2015

I was getting confused between location/GPS events and map position change events.

@bleege bleege modified the milestones: v0.1.0-android, v0.2.0-android Aug 26, 2015
@bleege bleege mentioned this issue Sep 3, 2015
@ljbade
Copy link
Contributor

ljbade commented Sep 24, 2015

In #2409 I'm cleaning up the updateMap() code so this should be unblocked by performance issues now.

@mikemorris
Copy link
Contributor

Have you tried sampling input/direction (I've used a constant rate of 15-20 times per second, but we could likely go lower) instead of trying to process or filter all events? I've done this in the past for handling user input from a gyroscope and accelerometer more smoothly in JavaScript, where it was previously choking on large bursts of minor change events.

Sample code at https://github.com/mikemorris/gyrocopter/blob/master/gyrocopter.js

@bleege bleege modified the milestones: android-v0.1.1, android-v0.2.0 Oct 1, 2015
@ljbade
Copy link
Contributor

ljbade commented Oct 2, 2015

Hmm I might have accidentally removed the user tracking stuff in #2002, but the code is still there in git history so perhaps we can have a go at making it really good this time.

Lets start with just location/GPS (and heading?) tracking and work on compass after.

Should we also hit the UI side of getting our GPS dot looking better?

@ljbade
Copy link
Contributor

ljbade commented Oct 2, 2015

Im thinking we eventually want a few modes (start with first two):

  • no tracking
  • just location tracking
  • location tracking and map heading/rotation from GPS direction
  • location tracking and map heading/rotation from rate limited compass

Also do we make touch events cancel tracking (separate for rotation and pan events). Or leave that up to the app via the listening events.

@bleege bleege modified the milestones: android-v2.0.0, android-v2.1.0 Oct 2, 2015
@tobrun
Copy link
Member

tobrun commented Oct 8, 2015

Discussed with @bleege,
Important part here is that while zooming the GPS marker 'jitters' and shown GPS location is wrong.
If that problem is identified and fixed, I will start looking at optimising the bearing part.

@ljbade ljbade added the P1 label Oct 27, 2015
@bleege bleege modified the milestones: android-v2.2.0, android-v2.3.0 Oct 28, 2015
@bleege bleege modified the milestones: android-v2.3.0, android-v2.4.0 Dec 4, 2015
@tobrun
Copy link
Member

tobrun commented Dec 8, 2015

I'm working on this again, because I have noticed 2 bugs on current progress that need to fixed asap

@tobrun
Copy link
Member

tobrun commented Dec 17, 2015

To clarify above:

@bleege bleege modified the milestones: android-v3.0.0, android-v3.1.0 Dec 21, 2015
@tobrun
Copy link
Member

tobrun commented Dec 23, 2015

The new camera API from @bleege will help resolve remaining issue on this ticket:

#3396 contains the fix for animated location updates with user tracking mode enabled.

Todo list to close this issue:

@Buckley404
Copy link

Is this working correctly now?

Currently when I try to set up tracking in the onCreate it draws the blue marker in the top left corner, digging through the code on git I found that this was because the position of the marker is being set relative to the mapview by dividing width and height by 2 (height and width would be 0 while onCreate is being called).

I altered my code to include a button I could press to start tracking in order to bypass the problem, however even though the screen is centred on the correct position, the blue dot does not draw to the screen.

In the UserLocationView class and in the update method, why are you setting the blue marker position by dividing the screen/height width by 2 to find the centre point of the screen. Why not use the latitude and longitude to draw the marker like you would with a regular addMarker call or a screen centre?

If the code even worked properly, wouldn't moving around the map with user input reposition the blue dot in the wrong place i.e. keep it in the centre of the screen no matter where the user navigates to on the map?

@tobrun
Copy link
Member

tobrun commented Jan 5, 2016

@Buckley404, reading through your comment I believe you are using the incorrect method. If you want the user location to show on the map in similar fashion as a marker you should call

nMapView.setMyLocationEnabled(true);

instead of:

nMapView.setMyLocationTrackingMode(MyLocationTrackingMode.TRACKING_FOLLOW);

Let me know if you have any other questions.

@tobrun
Copy link
Member

tobrun commented Jan 5, 2016

#3397 landed with f80673b

@tobrun tobrun closed this as completed Jan 5, 2016
@tobrun
Copy link
Member

tobrun commented Jan 5, 2016

One thing I need to add to this is that current compass implementation is not on par with the one from Google. Current implemented code using accelerometer and magnetometer is generally spoken the accepted way of implementing a compass (as seen in books, SO and tutorials). It seems Google is adding some extra elements to the equitation or using another configuration to calculate values. One of the most notable differences is that Google's implementation is not impacted when switching perspective or tilting the device.

@Buckley404
Copy link

Thanks again @tobrun, I'll recheck my code after work however I think I was using both methods. I must have just confused myself. FYI google might just be setting minimum thresholds for when the compass should be affected by gyro.

@tobrun
Copy link
Member

tobrun commented Jan 5, 2016

@Buckley404 I have been trying to mimic their behaviour for quite some time and I now believe that Google is doing something different than just using the sensors as we are doing.
FYI I added thresholds in latest code, we could further optimise this by implementing a low pas filter.

@bleege bleege mentioned this issue Jan 13, 2016
12 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
Projects
None yet
Development

No branches or pull requests

8 participants