flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.04k stars 503 forks source link

Can't use web user tracking with controller #1408

Closed aardrop closed 6 months ago

aardrop commented 8 months ago

I seem only to be able to focus on the user with the built-in "Find my Location" component from Mapbox gl, which doesn't seem to be in this repository at all, and none of the methods we're using allow us to focus on the user.

Further, the user icon seems to only show up on the map if that "find my location" button is clicked, so there's no way for us to use Dart to trigger that event from my research. Has anyone gotten this to work?

I know there's only one tracking mode that works with the web, but I can't seem to actually see or focus on the user's location with Mapbox. I can build a workaround, but this is native to iOS and Android already, so I wanted to see if we could do this for the web.

Screenshot 2024-01-29 at 10 48 04 AM
aardrop commented 8 months ago

This is my workaround incase anyone else is struggling, would love to fix this in a more sustainable way.

Future<void> focusOnUser({bool initial = false}) async {
    if (kIsWeb) {
      loc.Location location = new loc.Location();
      loc.LocationData _locationData;
      _locationData = await location.getLocation();
      final latLng = LatLng(_locationData.latitude!, _locationData.longitude!);

      if (initial) {
        await mapController.addCircle(CircleOptions(
          geometry: latLng,
          circleRadius: 7,
          circleColor: "#007DAD",
          circleStrokeWidth: 2,
          circleStrokeColor: "#FFFFFF",
        ));
      }

      await mapController.animateCamera(
        CameraUpdate.newLatLngZoom(
          latLng,
          10,
        ),
      );
      return;
    } else {
      await mapController
          .updateMyLocationTrackingMode(MyLocationTrackingMode.Tracking);
    }
  }
stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.