getMapDataBy method
Future<GeocodeResponse>
getMapDataBy({
- String address = '',
- String lat = '',
- String lng = '',
- String placeId = '',
- ComponentsFilter? componentsFilter,
You must supply one, and only one, of the following fields.
address
: The address which you want to geocode.
lat
and lng
: The LatLng for which you wish to obtain the closest, human-readable address.
placeId
: The place ID of the place for which you wish to obtain the closest, human-readable address.
componentsFilter
: You can set the Geocoding Service to return address results restricted to a specific area, by
using a components filter
developers.google.com/maps/documentation/javascript/geocoding#ComponentFiltering
Implementation
Future<GeocodeResponse> getMapDataBy(
{String address = '',
String lat = '',
String lng = '',
String placeId = '',
ComponentsFilter? componentsFilter}) async {
if (lat.isEmpty && lng.isEmpty || lat.isNotEmpty && lng.isNotEmpty) {
Map<String, dynamic> _queryParameter;
if (placeId.isEmpty) {
_queryParameter = <String, dynamic>{
'key': _apiKey,
'address': '$address',
'latlng': '$lat,$lng',
'components':
componentsFilter == null ? '' : componentsFilter.toJson(),
};
} else {
_queryParameter = <String, dynamic>{
'key': _apiKey,
'place_id': '$placeId'
};
}
print(_queryParameter);
GeocodeResponse _geocodeResponse =
await _mapSearchCubit.getGeocodeData(_queryParameter);
print('ADDRESS :: ');
print(_geocodeResponse.toJson());
return _geocodeResponse;
} else {
throw ('Either lat & lng should be empty nor lat & lng should fill up');
}
}