如何使用位置在颤振中转换纬度和经度

how to convert latitude and longitude in flutter using location

我想将经纬度转换为地址,但我不知道如何,这是我编写的代码:

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

我想要 snapshot.data!.latitude 和 longitude 作为地址

您可以使用geocoding从纬度和经度获取地址

List<Placemark> placemarks = await placemarkFromCoordinates(40.6971494, -74.2598717);
print(placemarks[0].country.toString() +
        "::" +
        placemarks[0].administrativeArea.toString() +
        "::" +
        placemarks[0].subAdministrativeArea.toString());

结果

United States::New Jersey::Union County

你可以使用plugin,然后是下面的代码,

List<Placemark> placemarks = await placemarkFromCoordinates("${snapshot.data!.latitude}", "${snapshot.data!.longitude}");

那么,

Text("${placemarks[0].country}")
Text("${placemarks[0].administrativeArea}")