Search code examples
flutterlocation

how to convert latitude and longitude in flutter using location


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


Solution

  • 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}")