未经手的例外:用户拒绝访问设备位置的权限
getUserLocationAddress() async
{
Position newPosition = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high
);
position = newPosition;
placemarks = await placemarkFromCoordinates(
position!.latitude, position!.longitude
);
Placemark pMark = placemarks![0];
String fullAddress = '${pMark.subThoroughfare}
${pMark.thoroughfare}, ${pMark.subLocality} ${pMark.locality}, ${pMark.subAdministrativeArea}, ${pMark.administrativeArea} ${pMark.postalCode}, ${pMark.country}';
_locationController.text = fullAddress;
_flatNumber.text = '${pMark.subThoroughfare} ${pMark.thoroughfare}, ${pMark.subLocality} ${pMark.locality}';
_city.text = '${pMark.subAdministrativeArea}, ${pMark.administrativeArea} ${pMark.postalCode}';
_state.text = '${pMark.country}';
_completeAddress.text = fullAddress;
}
我已经添加了此函数(),但是它可以进行记录并显示位置。
screenShot 即使按下“获取我的位置”后,它也不会显示位置。请帮助
getUserLocationAddress() async
{
Position newPosition = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high
);
position = newPosition;
placemarks = await placemarkFromCoordinates(
position!.latitude, position!.longitude
);
Placemark pMark = placemarks![0];
String fullAddress = '${pMark.subThoroughfare}
${pMark.thoroughfare}, ${pMark.subLocality} ${pMark.locality}, ${pMark.subAdministrativeArea}, ${pMark.administrativeArea} ${pMark.postalCode}, ${pMark.country}';
_locationController.text = fullAddress;
_flatNumber.text = '${pMark.subThoroughfare} ${pMark.thoroughfare}, ${pMark.subLocality} ${pMark.locality}';
_city.text = '${pMark.subAdministrativeArea}, ${pMark.administrativeArea} ${pMark.postalCode}';
_state.text = '${pMark.country}';
_completeAddress.text = fullAddress;
}
I have added this function onPressed() but it doest record and show the location..
screenshot
even after pressing on 'Get My Location' it doesn't show location. pls help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个应用都需要权限访问设备的位置。
下面的代码,摘自 https://pub.dev/packages/geolocator 它。
Every app needs permission to access the device's location.
The code below, extracted from https://pub.dev/packages/geolocator, shows how to request it.