locate method
Tries to locate the current user location.
Return LatLng location if found, and optionally sets the map view to the user's location (or stay in previous location if geolocation failed).
Implementation
Future<LatLng?> locate([bool automove = false, double zoom = 17.0]) async {
log('MapStates locate');
_startLocating();
await _initLocationSettings();
try {
LocationData? data = await _location?.getLocation();
_stopLocating();
if (data != null) {
_position = LatLng(
data.latitude,
data.longitude,
data.altitude,
);
notifyListeners();
if (automove) {
await move(_position, zoom - 0.02, true);
}
return _position;
}
} catch (e) {
_stopLocating();
log(e);
}
return null;
}