Шаг-1
Добавьте эти два свойства в info.plist
NSLocationAlwaysUsageDescription
и ниже собственности
Шаг-2
на ваш взгляд Controlle г вызова метод делегата
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}
@property (strong, nonatomic) NSString *longitude;
@property (strong, nonatomic) NSString *latitude;
Шаг-3
on your Implementation File on your `viewDidLoad`
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[locationManager requestWhenInUseAuthorization];
}
[locationManager startUpdatingLocation];
}
Шаг-4
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
UIAlertView *errorAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"There was an error retrieving your location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorAlert show];
NSLog(@"Error: %@",error.description);
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *crnLoc = [locations lastObject];
latitude= [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.latitude];
longitude = [NSString stringWithFormat:@"%.8f",crnLoc.coordinate.longitude];
}
для образца см this и this
ваш вопрос не НКУ ar, не могли бы вы объяснить больше –
@ Anbu.Karthik я просто добавлю его –
как это возможно, бросить, какая цель u пробовала это –