getCurrentUserLocation function

Future<LatLng> getCurrentUserLocation({
  1. required LatLng defaultLocation,
  2. bool cached = false,
})

Implementation

Future<LatLng> getCurrentUserLocation(
    {required LatLng defaultLocation, bool cached = false}) async {
  if (cached && cachedUserLocation != null) {
    return cachedUserLocation!;
  }
  return queryCurrentUserLocation().then((loc) {
    if (loc != null) {
      cachedUserLocation = loc;
    }
    return loc ?? defaultLocation;
  }).onError((error, _) {
    print("Error querying user location: $error");
    return defaultLocation;
  });
}