Hello everyone I am trying to build a flutter to display the latitude and the longitude but I still get an error here is the code :
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
应该做你需要的。
Below code is working for me
var location = new Location();
location.onLocationChanged().listen((LocationData currentLocation) {
print(currentLocation.latitude);
print(currentLocation.longitude);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.