#import <CoreLocation/CoreLocation.h>
@property(strong,nonatomic)CLLocationManager *manager;
#pragma mark - 地图定位
-(void)initMapManager
{
_manager=[[CLLocationManager alloc]init];
_manager.delegate=self;
_manager.distanceFilter=kCLLocationAccuracyBest;
_manager.distanceFilter=5;
if (IOS8_OR_LATER) {
[_manager requestWhenInUseAuthorization];
}
if ([CLLocationManager locationServicesEnabled]) {
[_manager startUpdatingLocation];
}
else
{
NSLog(@"cant location");
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
// for (CLLocation *location in locations) {
// CLLocationCoordinate2D coordinate=location.coordinate;
// NSLog(@"---%f---%f",coordinate.latitude,coordinate.longitude);
// }
CLLocation *location=[locations lastObject];
CLLocationCoordinate2D coordinate=location.coordinate;
NSLog(@"---%f---%f",coordinate.latitude,coordinate.longitude);
}
本文介绍了一个iOS应用中实现地理位置更新的方法。通过初始化CLLocationManager并设置代理,应用可以在用户允许的情况下获取到当前的位置坐标。代码展示了如何请求位置服务授权、启动位置更新及处理更新后的地理位置。
3981

被折叠的 条评论
为什么被折叠?



