大家好,我正在尝试制作一个颤振以显示纬度和经度,但是这里仍然有一个错误:
void initState(){
super.initState();
//Default variable set 0
currentLocation['latitude'] = 0.0;
currentLocation['longtitude'] = 0.0;
initPlatformState();
locationSubscription = location.onLocationChanged.listen((Map<String, double> result){
setState(() {
currentLocation = result;
});
});
}
答案 0 :(得分:1)
onLocationChanged
是一个函数,因此您需要调用它以返回流onLocationChanged().listen
应该满足您的要求。
答案 1 :(得分:0)
下面的代码对我有用
var location = new Location();
location.onLocationChanged().listen((LocationData currentLocation) {
print(currentLocation.latitude);
print(currentLocation.longitude);
});