Flutter Native - GPS Positioning
This guide covers how to use GPS positioning with the Wemap SDK, including required permissions and configuration.
Overview
GPS is the default location source. It uses the device's built-in GPS (and assisted positioning) to determine the user's location. It works best outdoors and in buildings with good satellite visibility.
Use GPS when:
- Your app is used outdoors (navigation, outdoor maps)
- Indoor precision is not critical
- You want minimal permissions (no camera)
Permissions
GPS requires location permission only.
Android
Add to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
iOS
Add to ios/Runner/Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need access to your location to show your position on the map and provide navigation.</string>
If you use the permission_handler package, add to your Podfile's post_install block:
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
'PERMISSION_LOCATION=1',
]
Enabling GPS
GPS is the default. You can set it explicitly:
MapOptions(
mapID: yourMapId,
token: yourToken,
environment: Environment.PROD,
locationSource: LocationSource.GPS, // Default; can be omitted
)
Locating the user with GPS
After granting location permission and once the map is ready, call mapManager.locateMe() to request the user's GPS position. The blue dot will appear on the map and the camera will center on the user.
late MapManager _mapManager;
void _onMapReady(MapData mapData, MapManager mapManager) {
_mapManager = mapManager;
// Ensure location permission is granted, then locate the user
_locateUser();
}
Future<void> _locateUser() async {
// Request permission if needed (e.g. using permission_handler)
await _mapManager.locateMe();
}
User location button
With userLocationButtonEnabled: true, users can tap a button to center the map on their GPS position. The SDK will request location permission when needed.
WemapMap(
options: mapOptions,
userLocationButtonEnabled: true,
)
Retrieving user location
After the map is ready, you can access user position and attitude via MapManager, which is provided in the onMapReady callback. Ensure location permission is granted.
| Method | Description |
|---|---|
mapManager.getUserLocation() | Get current user position once. Returns Coordinate? with latitude, longitude, level. Returns null if location is not yet available. |
mapManager.getUserLocationStream() | Stream<Coordinate> — continuous position updates |
mapManager.getUserAttitudeStream() | Stream<Attitude> — device heading (headingDegrees 0–360) for the blue dot arrow |
void _onMapReady(MapData mapData, MapManager mapManager) {
mapManager.getUserLocation().then((coordinate) {
if (coordinate != null) {
print('User at: ${coordinate.latitude}, ${coordinate.longitude}');
}
});
}
// Or listen to continuous updates
mapManager.getUserLocationStream().listen((coordinate) {
// Handle each position update
});