步骤-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
你的问题不是CLE AR,你能解释一下吗 –
@ Anbu.Karthik我只是加了它 –
怎么可能兄弟,你试过这个的目的是什么 –