getAddress method
Future<FMData?>
getAddress({})
Get address from coordinates (Reverse Geocoding)
Implementation
Future<FMData?> getAddress({
required double lat,
required double lng,
int maxRetries = 3,
Function(Object, StackTrace)? onError,
}) async {
assert(maxRetries <= 5, 'Keep maxRetries less than or equal to 5');
try {
final query = {'lat': lat, 'lon': lng, 'zoom': 18, 'format': 'jsonv2'};
String url = _baseURL;
url += _reverseEndpoint;
url += '?${query.keys.map((k) => '$k=${query[k]}').join('&')}';
final res = await http.get(Uri.parse(url));
return FMRawData.fromJSON(jsonDecode(res.body)).data;
} catch (e, st) {
if (maxRetries > 0) {
return getAddress(lat: lat, lng: lng, maxRetries: --maxRetries);
}
if (onError != null) onError(e, st);
return null;
}
}