mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
282 stars 116 forks source link

User location Tracking methods as found in 'mapbox_gl' #248

Open PrettyCodes opened 1 year ago

PrettyCodes commented 1 year ago

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,
}
Xennis commented 1 year ago

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

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

3) Turn off the tracking if the user scrolls:

      onScrollListener: (ScreenCoordinate coordinate) {
        if (_userlocationTracking) {
          _userlocationTracking = false;
        }
      },
aamirki commented 8 months ago

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?

tomblixt commented 7 months ago

+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.

basvdijk commented 6 months ago

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