decodeAddress method

Future<AddressComponent> decodeAddress({
  1. required String address,
})

The decodeAddress function decodes an address into an AddressComponent by retrieving location and placemark information asynchronously.

Args: address (String): The decodeAddress function takes a String parameter address which represents the address that needs to be decoded into an AddressComponent. The function uses the locationFromAddress and placemarkFromCoordinates functions to retrieve the location and placemark information based on the provided address

Returns: A Future<AddressComponent> is being returned from the decodeAddress function.

Implementation

Future<AddressComponent> decodeAddress({required String address}) async {
  try {
    List<Location> locations = await locationFromAddress(address);
    List<Placemark> placemarks = await placemarkFromCoordinates(
      locations.first.latitude,
      locations.first.longitude,
    );

    return _createAddressComponent(
      Position(
        latitude: locations.first.latitude,
        longitude: locations.first.longitude,
        timestamp: DateTime.now(),
        accuracy: 0,
        altitudeAccuracy: 0,
        headingAccuracy: 0,
        altitude: 0,
        heading: 0,
        speed: 0,
        speedAccuracy: 0,
      ),
      placemarks.first,
    );
  } catch (e) {
    rethrow;
  }
}