#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 使用您的位置獲取當前的位置信息,通過設置頁面的隱藏位置功能可隨時手動隱藏位置信息。
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。