mapbox-maps-flutter icon indicating copy to clipboard operation
mapbox-maps-flutter copied to clipboard

User location Tracking methods as found in 'mapbox_gl'

Open PrettyCodes opened this issue 2 years ago • 4 comments

Hi,

I am porting my Flutter app from 'mapbox_gl' to this official library day by day and found that there is no similar implementation of Tracking modes as found in 'mapbox_gl'. I am not talking about location tracking as I am using geolocation and other libraries for that, but basically in-built tracking and displaying the user's location puck on the map in different ways, such as by compass (keeps up the location bearing).

'mapbox_gl' handles this very well and comes in very handy for great UX. I believe this feature will be useful for many, and I am open to contributing to this if someone can point me in the right direction as I am a bit new to hard-code Dart & Flutter programming.

For now, I am working on implementing this locally but not sure if it would be well worth the time and may keep my keep my app on 'mapbox_gl' for longer.

Reference from 'mapbox_gl':

/// The camera mode, which determines how the map camera will track the rendered location.
enum MyLocationTrackingMode {
  None,
  Tracking,
  TrackingCompass,
  TrackingGPS,
}

PrettyCodes avatar Sep 26 '23 17:09 PrettyCodes

For people who stumble over this too:

How I solved it:

  1. Use the Mapbox controller to enable the user location (with MapboxMap _mapboxMap):
    await _mapboxMap.location.updateSettings(LocationComponentSettings(
        enabled: true,
        pulsingEnabled: false,
        showAccuracyRing: true,
        puckBearingEnabled: true));
  1. Write a function that regularly updates the camera (with Timer? _timer and bool _userlocationTracking):
  void refreshTrackLocation() async {
    _timer?.cancel();
    _timer = Timer.periodic(const Duration(milliseconds: 900), (timer) async {
      if (!_userlocationTracking) {
        _timer?.cancel();
        return;
      }

      final Position puckLocation = await _mapboxMap.style.getPuckPosition();
      
      // Some function that changes the camera of the map.
      _setCameraPosition(puckLocation);
  }
  1. Turn off the tracking if the user scrolls:
      onScrollListener: (ScreenCoordinate coordinate) {
        if (_userlocationTracking) {
          _userlocationTracking = false;
        }
      },

Xennis avatar Sep 27 '23 21:09 Xennis

Are there plans to officially add this feature to this library? Maintaining a workaround to manually set tracking and updating of the viewport based on a Timer doesn't work as well as mapbox_gl's built in solution so it would be very helpful to have this officially supported in the library. Not too familiar with how mapbox_gl implements this, is it a supported feature in the iOS/Android SDK that can be supported in this flutter library?

aamirki avatar Feb 20 '24 18:02 aamirki

+1. It would be really nice to have the same tracking modes as mapbox_gl. Otherwise something like the LocationManager/addLocationConsumer is a must-have.

tomblixt avatar Mar 27 '24 17:03 tomblixt

This issue looks related to https://github.com/mapbox/mapbox-maps-flutter/issues/33 It seems they are working on it.

basvdijk avatar Apr 18 '24 16:04 basvdijk