大家好我正在尝试建立一个颤振来显示纬度和经度,但我仍然得到一个错误,这里是代码:
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;
});
});
}
onLocationChanged
是一个函数,所以你需要调用它来取回流onLocationChanged().listen
应该做你需要的。
下面的代码对我有用
var location = new Location();
location.onLocationChanged().listen((LocationData currentLocation) {
print(currentLocation.latitude);
print(currentLocation.longitude);
});