您好,如我在标题中所写,我该如何实现?我已经获得了位置许可,但无法打开位置!
答案 0 :(得分:2)
您可以使用系统对话框并要求用户启用它。选中此link供参考。
创建平台特定的频道,并在用户希望启用它时调用它。
答案 1 :(得分:2)
它将打开设置。因此用户可以启用它。据我所知,这是最佳做法。
安装插件:
https://pub.dartlang.org/packages/android_intent#-installing-tab-
导入您的飞镖:
void openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
添加方法:
Model model = ModelFactory.createDefaultModel();
RDFDataMgr.read(model, new StringReader(message), null, Lang.JSONLD);
RDFDataMgr.write(System.out, model, Lanmg.TURTLE);
调用完成...
答案 2 :(得分:1)
首先在pubspec.yaml中添加此依赖项:
location: ^1.4.0
然后,使用此功能来检索设备的当前位置:
import 'package:location/location.dart';
Future<String, double> getCurrentLocation() async {
var currentLocation = <String, double>{};
var location = new Location();
// Platform messages may fail, so we use a try/catch PlatformException.
try {
currentLocation = await location.getLocation();
} catch (e) {
currentLocation = null;
print('Location Error:' + e.toString());
}
return currentLocation; //Format : "lat,lon
}
答案 3 :(得分:1)
我将使用从this链接中学到的知识来指导您。
将此依赖项添加到pubspec.yaml
dependencies:
location: ^3.0.0
现在,将以下软件包导入您的.dart
文件
import 'package:location/location.dart';
现在在函数内部,使用弹出框询问用户的位置,您可以执行以下操作
Location location = new Location();
bool _serviceEnabled;
LocationData _locationData;
以上是我们将在以下代码中使用的声明-
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
debugPrint('Location Denied once');
}
}
现在,您可以根据需要使用上面的代码段,通过弹出窗口进行“位置”请求调用,次数不限。
如果已授予用户位置信息,则可以使用以下行来存储和使用位置数据。
_locationData = await location.getLocation();
如果未授予该位置,则上一行将导致程序失败,因此请确保仅在用户允许从弹出窗口访问位置时才使用上一行。
希望这会有所帮助。干杯!
答案 4 :(得分:0)
flutterlocation插件向您显示了像本地android一样打开gps的对话框