如何从扑中的坐标获取位置名称?
问题描述:
我想要一个可以获取用户位置并使用GPS显示地点名称的按钮。
I wanted a button that can get the location of the user and display the place name using GPS.
我尝试了地图视图,但只能获得经度和纬度。
I tried map_view but it only can get latitude and longitude.
答
使用 geocoder 插件
,它会为您提供 findAddressesFromCoordinates
导入'package:geocoder / geocoder.dart';
import 'package:geocoder/geocoder.dart';
示例;
final coordinates = new Coordinates(1.10, 45.50);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
first = addresses.first;
print("${first.featureName} : ${first.addressLine}");
注意:
您也可以使用地理定位插件可获取很多有用的信息,例如检索最近的已知位置
NOTE: you can also use geolocation plugin to get a lot of useful information like Retrieving last known location