I want to convert latitude and longitude to address but I don't know how, here's the code I made:
void dispose() {
locationService.dispose();
super.dispose();
}
return StreamBuilder<UserLocation>(
stream: locationService.locationStream,
builder: (_, snapshot) => (snapshot.hasData) ? Scaffold(
appBar: AppBar(
title: Text("Order"),
actions: [
IconButton(onPressed: () => logout(), icon: Icon(Icons.logout))
],
),
body: ListView(
children: [
Column(
children: <Widget>[
Text("Latitude"
),
Text("${snapshot.data!.latitude}"
),
Text("Longitude"
),
Text("${snapshot.data!.longitude}"
),
I want snapshot.data!.latitude and longitude to be addresses
CodePudding user response:
You can use geocoding to get address from latitude and longitude
List<Placemark> placemarks = await placemarkFromCoordinates(40.6971494, -74.2598717);
print(placemarks[0].country.toString()
"::"
placemarks[0].administrativeArea.toString()
"::"
placemarks[0].subAdministrativeArea.toString());
result
United States::New Jersey::Union County
CodePudding user response:
You can use plugin, and then bellow code,
List<Placemark> placemarks = await placemarkFromCoordinates("${snapshot.data!.latitude}", "${snapshot.data!.longitude}");
then,
Text("${placemarks[0].country}")
Text("${placemarks[0].administrativeArea}")