fetchLocation method
Returns a Location
Implementation
Future<dynamic> fetchLocation() {
Completer completer = Completer<Map<String, dynamic>>();
MapOptions _mapOptions = MapOptions(
zoom: 0,
viewMode: '2D',
);
AMap aMap = AMap('location', _mapOptions);
aMap.plugin(['AMap.Geolocation'], allowInterop(() {
Geolocation geolocation = Geolocation(GeoOptions());
aMap.addControl(geolocation);
geolocation.getCurrentPosition(allowInterop((status, result) {
if (status == 'complete') {
completer.complete(Location(
latLng: LatLng(result.position.lat, result.position.lng),
country: result.addressComponent.country,
province: result.addressComponent.province,
city: result.addressComponent.city,
district: result.addressComponent.district,
street: result.addressComponent.street,
address: result.formattedAddress,
accuracy: 0.0,
).toJson());
} else {
completer.completeError(result.message);
}
}));
}));
return completer.future;
}