简体   繁体   中英

CLLocationManager updates location when user select location button

In my application ,in initial lunch i have to used cllocationmanager class to find current location ([locationManager startUpdatingLocation];) using this method.After find a location i fired this method ([locationManager stopUpdatingLocation];).

Now a user will move from one place to other place.It will automatically detects newlocation or we need to fire ([locationManager startUpdatingLocation];) this method again.

Help me?

Note:

If i will call ([locationManager startUpdatingLocation];) method again it will give a newlocation or old location.How to differentiate it ?

Whenever you call [locationManager startUpdatingLocation];, this will give you the current location. So, when you call this function again it will give you new location.

In such case, either you have to continuously keep on watch for the updated location, if you want automatic update or after certain duration of time you have to check again for updated location and compare it with previous one. By doing this, you will come to know weather is it new location or old.

Short answer: YES, you need to call [locationManager startUpdatingLocation]; to get a new location. You can stop and then start and then stop and then start, and each time you start, you will get the current (new) location of the device.

Long answer: You can also choose to keep the locationManager on (never call stopUpdatingLocation) and get updates all the time. By setting the distanceFilter property for the locations manager, you can choose when (or, to be exact, at what distance delta from last update) a new location update will be sent to your app. This seems to be the way used in most implementations that take more than one location sample, or need to track the location of the user constantly.

Also note, there is a new startMonitoringSignificantLocationChanges which gives different way to get updates: read the documentation carefully if you want to use this feature, it is not always available.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM