Reputation: 309
what's the efficient way to keep track user's location? I mean I do not care if the location has been change slightly, because it will waste the resources.
i used in my code: LocationManager.stopUpdatingLocation()
to stop every small changes in location...
is there a way to keep track the location only if it oldLocation and newLocation has big different?
Upvotes: 0
Views: 244
Reputation: 3956
Yes there are two ways you can achieve that. First way is to use
func startMonitoringSignificantLocationChanges()
startMonitoringSignificantLocationChanges
starts the generation of updates based on significant location changes. Apps can expect a notification as soon as the device moves 500 meters when you are using startMonitoringSignificantLocationChanges
. And if you want to use startUpdatingLocation
then set distanceFilter
to distance of your choice and it will report location only if location change is more than distance specified in filter. distanceFilter
represents the minimum distance (measured in meters) a device must move horizontally before an update event is generated.
Upvotes: 2