地理定位器位置不会显示在控制台中



Geolocator位置没有出现在控制台中,也没有错误。我曾尝试使用position.longitude单独获取经度和纬度,但没有任何变化,问题出在这条线上,但我无法确定:position position=wait Geolocator.getCurrentPosition(desiredAccuracy:LocationAccuracy.high(;

这是代码:

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
class LoadingScreen extends StatefulWidget {
@override
_LoadingScreenState createState() => _LoadingScreenState();
}
class _LoadingScreenState extends State<LoadingScreen> {
void getLocation() async{
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
getLocation();
//  _determinePosition();
//Get the current location
},
child: Text('Get Location'),
),
),
);
}
}

AndroidManifest.xml中添加以下访问位置的权限。

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

检查是否启用服务。

bool servicestatus = await Geolocator.isLocationServiceEnabled();
if(servicestatus){
print("GPS service is enabled");
}else{
print("GPS service is disabled.");
}

现在尝试获取位置详细信息。

Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(position.longitude); //Output: 80.24599079
print(position.latitude); //Output: 29.6593457

相关内容

  • 没有找到相关文章

最新更新