![](/img/trans.png)
[英]How to Convert latitude and Longitude to Address by using Location Plugin in Flutter
[英]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 作為地址
您可以使用地理編碼從緯度和經度獲取地址
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}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.