romanejaquez / flutter_locationupdates

Sample Flutter project displaying real-time location updates on a Google Map
175 stars 119 forks source link

how to stop location tracking #1

Open rajatjain7869 opened 4 years ago

rajatjain7869 commented 4 years ago

this is Good example for live tracking but how we will stop the location updates or you can say location listener updates

romanejaquez commented 4 years ago

@rajatjain7869 if you want to stop location updates, you have to capture the stream subscription from the location.onLocationChanged().listen, as such:

locationData = location.onLocationChanged().listen((LocationData cLoc) { currentLocation = cLoc; updatePinOnMap(); });

then anywhere you want to stop it, then you say:

locationData.cancel() or locationData.pause();

if you want to pick it back up, then you say:

locationData.resume();

Hope that helps!

sokunsamnang commented 4 years ago

@rajatjain7869 if you want to stop location updates, you have to capture the stream subscription from the location.onLocationChanged().listen, as such:

locationData = location.onLocationChanged().listen((LocationData cLoc) { currentLocation = cLoc; updatePinOnMap(); });

then anywhere you want to stop it, then you say:

locationData.cancel() or locationData.pause();

if you want to pick it back up, then you say:

locationData.resume();

Hope that helps!

aftter add .cancel(); or .pause(); , function showPinsOnMap(); not load (sourcePinInfo, destinationPinInfo).