我刚刚开始颤振,当我无法在 iOS 模拟器上使用地理定位器插件获得准确的坐标时,我不确定为什么。
它返回这个,它是 1 个小数点并给出一个不准确的位置
纬度: 1.3, 长: 103.8
我怎样才能让它返回这个?
1.3825983,103.8814173
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:geolocator/geolocator.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
class Home extends StatefulWidget {
Home(this.listType);
final String listType;
@override
_HomeState createState() => new _HomeState();
}
class _HomeState extends State<Home> {
GoogleMapController _mapController;
// final LatLng _center = const LatLng(1.290270, 103.851959);
Position _pos;
Widget _mapWidget;
void _onMapCreated(GoogleMapController controller) {
_mapController = controller;
}
@override
void initState() {
_mapWidget = SpinKitRotatingCircle(
color: Colors.white,
size: 50.0,
);
getCurrentLocation();
super.initState();
}
void getCurrentLocation() async {
GeolocationStatus geolocationStatus = await Geolocator().checkGeolocationPermissionStatus();
print(geolocationStatus);
Position currPos = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.best);
print(currPos);
setState(() {
_pos = currPos;
_mapWidget = initMapWidget();
});
}
Widget initMapWidget () {
return GoogleMap(
mapType: MapType.normal,
onMapCreated: _onMapCreated,
myLocationEnabled: true,
initialCameraPosition: CameraPosition(
target: LatLng(_pos.latitude, _pos.longitude),
zoom: 15.0,
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: _mapWidget,
),
);
}
}
尝试解析lat
并long
double
。
target: LatLng(_pos.latitude.toDouble(), _pos.longitude.toDouble()),
尝试将定位精度标记为高
Position currPos = await Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
print(currPos);