1.首先要導(dǎo)入CoreLocation ?這個(gè)框架
2.然后要用到這個(gè)類CLLocationManager
@property(nonatomic,strong)CLLocationManager* manger;
3.添加一下代理<CLLocationManagerDelegate>
4.下面是初始化一下本類和綁定代理(如果喜歡懶加載可以寫成懶加載)
_manger= [[CLLocationManager alloc]init];
_manger.delegate=self;
//下面是開始定位
[_manger startUpdatingLocation];
5.然后定位成功后就會(huì)走下面代理方法
- (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);
}