I am working in the cllocation manager and get the current location of user but unable to find the user status like user is in running position or stop position . So please help me , How can get its corrent status when user walking programmatically in iphone.
Use the speed attribute of CLLocation, asumimg GPS enabled and set to best accuracy.
If (loc.speed > 7/3.6) then running
walking: < 6 km/h
stopped is more difficult: no location update (measured with a timer)
But you cannot distinguish between "stopped" and "no GPS available" (e.g in underground, or indoors). That would need the acceleration sensor, if the state needs to be in real time.
Hello everyone I am using CoreLocation in my project to get to know if I have reached a certain region. I am not using startMonitoringForRegion but instead I am using startMonitoringForSignificantLocationChange in the background.
So when I have a location update I check against my stored place and if distance is less or equal my set radius it will send a local notification. Everything works fine except let's say that the user is in the range and he receives the push. Again when he goes in background walk a bit it will certainly show the notification. How to cater for this i.e since I received a notification it wont pop up again and also if when I left that region and re enter will should pop up. I was thinking to use a Boolean value to check.
You may clear notifications in
- (void)applicationDidBecomeActive:(UIApplication *)application
[[UIApplication sharedApplication] cancelAllLocalNotifications];
And recreate a local notifications excluding the region where you are now
My suggestion is not to use the
Boolean notified = FALSE;
value as it will loose its value when application get terminated and relaunched.
Why don't you use
[[NSUserDefaults standardUserDefaults] setValue:#"1" forKey:#"notified"];
As this not notify again and again when ever application restarted or relaunched.
I have an app which uses CLLocationManager to track the user's route, drawing dots along the path taken. The app runs in the background using Required background modes > App registers for location updates.
As I understand, anything that happens in the background needs to be called from locationManager:didUpdateToLocation:fromLocation as this is the method that gets called with each location update.
The problem I'm having is that sometimes this stops getting called. It seems to happen when the user's location does not change much within the space of maybe 15 minutes or so. As far as I can tell, calls to locationManager:didUpdateToLocation:fromLocation just stop, presumably to save the battery. Unfortunately, it doesn't resume again when you're back on the move.
I presume there's no way to override this behaviour, so I would like to use Notification Centre to inform the user that the app is no longer recording the route. The problem is, how can the app know that this has happened? If locationManager:didUpdateToLocation:fromLocation is not called, I can't fire my notification. If it is being called, the notification should not fire.
Is there some kind of system notification that says location updates will cease?
I'm finding it quite hard to debug this as I can't take my Mac everywhere when I'm out and about testing the location on the device (there's only so much you can do in the simulator). Any tips for debugging would also be much appreciated!
If you haven't found the answer, I think it is because of a new attribute added to CLLocationManager called pausesLocationUpdatesAutomatically. The attribute defaults to YES, and its behaviour is exactly as you describe. Try setting it to NO and I think it will fix your problem.
Starting in iOS9, make sure you're also setting this property on your location manager:
[locationManager setAllowsBackgroundLocationUpdates:YES]
There's a delegate for location update did Fail
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
There are a few kinds of errors: kCLErrorDenied kCLErrorNetwork Add code here to handle them in the delegate method above not updating location, perhaps a UIAlertView to tell the user.
Personally, I call [locationManager stopUpdatingLocation]; on any error then restart it with an error message depending on the reason for the failure.
ALSO re background, check code in your appDelegate:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
[self saveContext];
if ([CLLocationManager significantLocationChangeMonitoringAvailable]) {
// Stop normal location updates and start significant location change updates for battery efficiency.
[self.locationHandler.locationManager stopUpdatingLocation];
[self.locationHandler.locationManager startMonitoringSignificantLocationChanges];
}
else {
NSLog(#"Significant location change monitoring is not available.");
}
}
LASTLY re: testing. You can simulate some errors in location by changing the location movement in the simulator. For example, going from running to driving will cause an error. Going from running to a single specific custom location will cause an error. They should all appear in the delegate method for locationManager above.
I've managed to solve the problem by adding a local notification that fires with a 90 second delay every time a new location is added to the route. When the next location is added, the previous notification is cancelled and a new one is scheduled. This way, if it stops updating, a notification is received by the user (albeit with a 90 second delay). It's not ideal, and it may not be great for battery life, but it is a solution and it's the best I've got for the time being.
#Ron, I meet the same problem as beev describe, and i had already set pausesLocationUpdatesAutomatically to NO. I think because iOS will kill some apps that didn't be triggered in 10 minutes when it's under background. So add local notification maybe a good choice at the moment.
I am using map functionality in my iphone app. I m showing stores for users current location on map.
Whenever user scrolls the map he needs to be shown stores of new location. eg. suppose user at
New York at first app will show New York stores but when he scrolls map to Texas then app should fire web service request for Texas location. My problem is
1) if web service request goes at each map scroll, app may crash or wait each time for response for new set of stores. (for this i m going to put some hardcoded radius to send request) So how to handle it proper way.
2) I want to know distance between two location so that i can send request to server only if the distance between 2 locations is greater than some specific value.
I am using map view delegates for above functionality. Please suggest me some proper way to handle it.
Thanks
Well to find the distance between 2 points i use
CLLocation *location1 = [[CLLocation alloc]initWithLatitude:[[dict valueForKey:#"lat"] doubleValue] longitude:[[dict valueForKey:#"lon"]doubleValue]];
float distance =[mUserCurrentLocation distanceFromLocation:location1]/1000;
float distanceinMeters=[mUserCurrentLocation distanceFromLocation:location1]; NSString *distancestr= [NSString stringWithFormat:#"%.2f KM",distance];
See If this can help you.
I found current location using (CLLocationManager startUpdatingLocation) this method. How long it takes to find current location ?(In minutes).
Because i want to set time out for CLLocationManger classes to stop updatinglocation.
Can anyone help me ? Thanks in advance.......
My location manager desiredAccuracy should be kCLLocationAccuracyBest and distancefilter should be kCLDistanceFilterNone.
If you started your stopwatch at moment when you entered into tunnel, you will get your gps coordinates immediately after you exit the tunnel.