User location
The Mapbox Maps SDK for Flutter enables your application to observe and respond to the user's location. It helps you request permission to access a user's location, use a location provider to get location information for the device, and display the user's location on the map visually.
To observe the user's location and show the location indicator on the map use LocationComponentSettingsInterface
accessible via MapboxMap.location
.
Configure permissions
You will need to grant location permission to use the location component of the Maps SDK for Flutter. You can use an existing library to request location permission, such as with permission_handler await Permission.locationWhenInUse.request();
will trigger permission request. You also need to declare the permission for both platforms:
Android
Add the following permissions to the manifest:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Learn how to request permission to show user location on Android.
iOS
Add the following to the Runner/Info.plist
to explain why you need access to the location data:
<key>NSLocationWhenInUseUsageDescription</key>
<string>[Your explanation here]</string>
Learn how to request permission to show user location on iOS.
Location puck
To customize the appearance of the location puck, call the MapboxMap.location.updateSettings
method.
To use the 3D puck with a model downloaded from URI instead of the default 2D puck :
mapboxMap.location.updateSettings(LocationComponentSettings(
locationPuck: LocationPuck(
locationPuck3D: LocationPuck3D(
modelUri:
"https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Duck/glTF-Embedded/Duck.gltf",))));
You can find more examples of customization in the sample app.