Location manager stops updating after 1 hour - ios

According my app requirement, we do tracking on, and its working fine. but problems comes when i enable GPS service on and never moves and place iPhone on desk for 1 hour after that i do journey of 30 minutes but my update location delegate never called this time.below is my code:
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.distanceFilter = 150.0f;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0")) {
setPausesLocationUpdatesAutomatically:NO];
}

Write this code :
[locationManager startUpdatingLocation];
& write their delegates methods also :
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSMutableString *latString = [NSMutableString stringWithFormat:#"%f",newLocation.coordinate.latitude];
NSMutableString *lngString = [NSMutableString stringWithFormat:#"%f",newLocation.coordinate.longitude];
}

Related

Offline Location Update is not working in iOS 14 and above

I am working on the Location update in my application
When the app is with internet connection location update (didUpdateLocation) is called. But when the app goes offline, Location update delegate is not called in iOS 14 . I am not getting the latitude and longitude.
Any idea why this is happening or is this the process of location manager?
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
if([locationManager respondsToSelector:#selector(requestWhenInUseAuthorization)]){
[locationManager requestWhenInUseAuthorization];
}else{
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
lattitude = [NSString stringWithFormat:#"%f", location.coordinate.latitude] ;
longitude = [NSString stringWithFormat:#"%f",location.coordinate.longitude];
[locationManager stopUpdatingLocation];
}

Geofence exit region delegate method triggered even device in stable position iOS (objective-c)

I have implemented geofence in my app. CLRegion radius is 200m. CLRegion boundary Exitregion delegate method triggers even when the device is in a stable position within CLRegion region.
Here is my code
locationmanager = [[CLLocationManager alloc] init];
locationmanager.delegate = self;
locationmanager.distanceFilter = kCLDistanceFilterNone;
locationmanager.desiredAccuracy = kCLLocationAccuracyBest;
[locationmanager requestAlwaysAuthorization];
if (locationmanager.locationServicesEnabled) {
[locationmanager startUpdatingLocation];
}
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(13.051404,
80.179970);
CLRegion *bridge = [[CLCircularRegion alloc]initWithCenter:center
radius:200.0
identifier:#"Bridge"];
[locationmanager startMonitoringForRegion:bridge];
[locationmanager startMonitoringSignificantLocationChanges];
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
NSLog(#"location notific %f %f",oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);
NSLog(#"location notific2 %f %f",newLocation.coordinate.latitude, newLocation.coordinate.longitude);
[locationManager stopUpdatingLocation];
}
Can anyone suggest me is there any solution for this?
You’re not using the geofence delegate method. You’re using the standard location delegate method. Search the docs for locationManager:didEnterRegion: and didExitRegion methods

Calling and releasing CLLocationManager With ARC

My app should get the user's current location only one time.
It's doing it successfully using the location manager and a delegate. Once i get the location for the first time my delegate calls the manager to stopUpdatingLocation.
Since I'm using ARC, and I keep an instance of this class during all the time my app runs, my CLLocationManager instance stays in memory.
I know GPS services are quite power consuming, but does it have the same effect while i actually don't consume more events? does it keep on working?
I want to know if i should add some logic to release it.
Try Following...
-(void)updateLoc
{
if (self.locationManager != nil)
{
[self.locationManager stopUpdatingLocation];
self.locationManager.delegate = nil;
self.locationManager = nil;
}
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
self.locationManager.headingFilter = 1;
self.locationManager.distanceFilter=10.0;
[self.locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
[self.locationManager stopUpdatingLocation];
self.locationManager = nil;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{//Use if you are supporting iOS 5
[self.locationManager stopUpdatingLocation];
self.locationManager = nil;
}

How to get current location latitude longitude in iphone?

i want to get my current location lat long for this i have written some code but i getting wrong place's lat long
here is my code.
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
float latitude = locationManager.location.coordinate.latitude;
float longitude = locationManager.location.coordinate.longitude;
To get the current location, write this code:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
locationManager.distanceFilter=kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
Then implement the delegate methods:
// CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
// Handle location updates
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
// Handle error
}
Set the delegate correctly: [locationManager setDelegate:self]
Implement the correct delegate method locationManager:didUpdateLocations:
Read out the locations array. The last item in the array is the most recent found location.

CLLocationManager not calling its delegate method

I am developing an app which involves tracking the new location and updates to the server in X mins. I am stopping the location updating when the time diff is equal to or greater than X mins, then sending to the server and then start updating the location if it is less than X mins. But the didUpdateToLocation delegate methos is not called when it is less than X mins.
I am posting my code here:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if (theDiff > 10.0f || myDate == nil)
{
[self stopUpdating];
}
else
{
[self.mLocationManager startUpdatingLocation];
}
}
try this.,
//in your .h
CLLocationManager *locationManager;
#property (nonatomic,retain) CLLocationManager *locationManager;
// Then synthesize it in your .m
#synthesize locationManager;
//in your viewDidLoad
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
This will call the method whwnever you move with your phone. You can check this by changing simulator locatin also.
Hope this helps., Thanks, happy coding.
try this in .m add this method , or if you have any other custom code post it
-(void)LocationWithTime
{
[CLController sharedInstance].locationManager.desiredAccuracy = 100.0;
[CLController sharedInstance].delegate = self;
BOOL locationAccessAllowed = NO ;
if( [CLLocationManager respondsToSelector:#selector(locationServicesEnabled)] )
{
locationAccessAllowed = [CLLocationManager locationServicesEnabled] ;
}
if(locationAccessAllowed == YES)
{
[[CLController sharedInstance].locationManager startUpdatingLocation];
}
}
this is the delegate method i have used -
-(void)newLocationUpdate:(NSString *)latvalue longValue:(NSString*)longvalue Error:(int) errCode
{
DebugLog(#"LatLong values %# %#", [UserContext sharedInstance].strLat, [UserContext sharedInstance].strLong);
self.strLALat = latvalue;
self.strLALong = longvalue;
[[CLController sharedInstance].locationManager stopUpdatingLocation];
[CLController sharedInstance].delegate=nil ;
}
Excerpt from Apple API Documentation,
/*
* locationManager:didUpdateToLocation:fromLocation:
*
* This method is deprecated. If locationManager:didUpdateLocations: is
* implemented, this method will not be called.
*/
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_6, __MAC_NA, __IPHONE_2_0, __IPHONE_6_0);
Use the below delegate method instead,
/*
* locationManager:didUpdateLocations:
* locations is an array of CLLocation objects in chronological order.
*/
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0);
This will work once you set the delegate.
Hope this helps.

Resources