1.首先要导入CoreLocation 这个框架
2.然后要用到这个类CLLocationManager
@property(nonatomic,strong)CLLocationManager* manger;
3.添加一下代理<CLLocationManagerDelegate>
4.下面是初始化一下本类和绑定代理(如果喜欢懒加载可以写成懒加载)
_manger= [[CLLocationManager alloc]init];
_manger.delegate=self;
//下面是开始定位
[_manger startUpdatingLocation];
5.然后定位成功后就会走下面代理方法
- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations {
[_manger stopUpdatingLocation];
CLLocation*location = [locations lastObject];
CLLocationDegreeslatitude = location.coordinate.latitude;
CLLocationDegreeslongitude = location.coordinate.longitude;
NSLog(@"%f%f",latitude,longitude);
}
网友评论