Reputation: 539
Is there any way to get the only device gps location using the corelocation in ios. Currently i am using the following code.
- (id)init{
if (!(self = [super init]))
return nil;
//Setup the manager
manager = [[CLLocationManager alloc] init];
if (!manager) {
return nil;
}
manager.distanceFilter = kCLDistanceFilterNone;
manager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
manager.desiredAccuracy = kCLLocationAccuracyBest;
manager.delegate = self;
if ([manager respondsToSelector:@selector(pausesLocationUpdatesAutomatically)]) {
manager.pausesLocationUpdatesAutomatically = NO;
}
if ([manager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[manager requestAlwaysAuthorization];
}
[manager startUpdatingLocation];
return self;
}
Upvotes: 0
Views: 875
Reputation: 371
You should add this code to your file. It is executed when a new location is received:
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
}
src: Getting the Users Location - Apple
Upvotes: 0