getAddressLatLng method

void getAddressLatLng(
  1. String address,
  2. LatLng? currentLocation
)

Adds location matching to address to atLocationSink. If currentLocation is passed then will add locations nearby the currentLocation.

Make sure that apiKey is passed while initialising.

Implementation

void getAddressLatLng(String address, LatLng? currentLocation) async {
  currentLocation ??= const LatLng(0, 0);

  var url =
      '$placesUrl?q=${address.replaceAll(RegExp(' '), '+')}&apiKey=${MixedConstants.API_KEY}&at=${currentLocation.latitude},${currentLocation.longitude}';

  var response = await http.get(Uri.parse(url));
  var addresses = jsonDecode(response.body);
  List data = addresses['results'];
  var share = <LocationModal>[];
  //// Removed because of nulls safety
  // for (Map ad in data ?? []) {
  for (Map ad in data) {
    if (ad['resultType'] == 'place') {
      share.add(LocationModal.fromJson(ad));
    }
  }

  atLocationSink.add(share);
}