humazed / google_map_location_picker

🌍 Map location picker component for flutter Based on google_maps_flutter
Apache License 2.0
206 stars 309 forks source link

How we can get area and city from address? #130

Open kadnan0900 opened 4 years ago

kadnan0900 commented 4 years ago

LocationResult result = await showLocationPicker( context, AppStrings.API_KEY, automaticallyAnimateToCurrentLocation: true, myLocationButtonEnabled: true, layersButtonEnabled: true, resultCardAlignment: Alignment.bottomCenter, );

How we can get area and city from result?

kadnan0900 commented 4 years ago

@humazed please guide how i can get city and address?

Rohan7654 commented 3 years ago

Hi, If your G-Map API Key is generated from billing account , then just use result.address to get the address and index it orderly to meet your requirement. If you're using a free API Key, you need to use a package https://pub.dev/packages/geolocator , as the google_map_location_picker will give you latlong only. Below is the code you can refer, `import 'package:geolocator/geolocator.dart'; LocationResult result = await showLocationPicker( context, AppStrings.API_KEY, automaticallyAnimateToCurrentLocation: true, myLocationButtonEnabled: true, layersButtonEnabled: true, resultCardAlignment: Alignment.bottomCenter, ); final Geolocator geolocator = Geolocator()..forceAndroidLocationManager; List p = await geolocator.placemarkFromCoordinates( result.latLng.latitude, result.latLng.longitude); Placemark place = p[0]; var area,city; area = place.subLocality.toString(); city = place.locality.toString();

}`