我有一個地圖和一個按鈕(如地圖應用程序一次)的視圖,允許用戶居中放大地圖上的當前位置。如果我不能使用locationServicesEnabled方法(總是返回YES),我應該創建一個BOOL屬性來檢查didFailWithError方法是否被調用,並知道我是否可以調用按鈕方法?檢查iOS定位服務
感謝您的閱讀。
編輯:
此代碼不會爲我工作。我正在使用模擬器。詢問locationServicesEnabled時,我總是收到YES。
// Gets the user present location.
- (IBAction)locateUser:(id)sender {
if([CLLocationManager locationServicesEnabled]) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = self.mapView.userLocation.location.coordinate.latitude;
coordinate.longitude = self.mapView.userLocation.location.coordinate.longitude;
[self zoomCoordinate:coordinate];
} else {
[[[[UIAlertView alloc] initWithTitle:@"Warning." message:@"Location services are disabled."
delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
}
}
我有發佈**優化位置權限檢查**在這篇文章,這一定會幫助你http://stackoverflow.com/questions/15153074/checking-location-service-permission-on-ios/35982887#35982887 – swiftBoy 2016-03-14 08:46:10