#import <CoreLocation/CoreLocation.h>
<CLLocationManagerDelegate>
self.locationManager=[[CLLocationManager alloc]init] ;
self.locationManager.delegate=self;
[self.locationManager startUpdatingLocation];
self.locationManager.distanceFilter=kCLLocationAccuracyBest;
[self.locationManager requestWhenInUseAuthorization];
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// 获取经纬度
NSLog(@"纬度:%f",newLocation.coordinate.latitude);
NSLog(@"经度:%f",newLocation.coordinate.longitude);
UIAlertView*alert=[[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"%f",newLocation.coordinate.latitude] message:[NSString stringWithFormat:@"%f",newLocation.coordinate.longitude] delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
[alert show];
// 停止位置更新
// [manager stopUpdatingLocation];
}
// 定位失误时触发
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"error:%@",error);
}
plist全新
Privacy - Location Usage Description 访问位置
Privacy - Location When In Use Usage Description 使用您的位置获取当前的位置信息,通过设置页面的隐藏位置功能可随时手动隐藏位置信息。
Privacy - Location Always Usage Description 使用您的位置获取当前的位置信息,通过设置页面的隐藏位置功能可随时手动隐藏位置信息。
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。