簡體   English   中英

IOS 8 Map無法正常工作:嘗試啟動MapKit位置更新而未提示位置授權

[英]IOS 8 Map is not working: Trying to start MapKit location updates without prompting for location authorization

我正在使用Xcode 6,當我嘗試使用CLLocationManager獲取用戶當前位置時遇到一些問題。 甚至我NSLocationAlwaysUsageDescription Info.plist文件中添加了NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription 並且還使用了[CLLocationManager requestWhenInUseAuthorization] 然后我也得到控制台輸出

2014-10-15 11:45:15.004 MapIOS8 [1916:57908]嘗試啟動MapKit位置更新,而無需提示位置授權。 必須首先調用-[CLLocationManager requestWhenInUseAuthorization]或-[CLLocationManager requestAlwaysAuthorization]。

您是否嘗試過按此順序編寫代碼?

CLLocationManager *YourLocationManager = [[CLLocationManager alloc] init];
YourLocationManager.delegate = self;
[YourLocationManager requestWhenInUseAuthorization];
[YourLocationManager startUpdatingLocation];

yourMapView.delegate = self;
yourMapView.showsUserLocation = YES;

另外,要獲取用戶位置坐標,您可能必須實現此mapkit委托方法

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    NSLog(@"%f, %f", userLocation.coordinate.latitude, userLocation.coordinate.longitude);

    [mapView selectAnnotation:userLocation animated:YES];
}

如果您使用的是iOS Simulator,請嘗試從“設置”->“常規”->“隱私”->“重置位置和隱私”重置位置設置。 然后致電:

[LocationManager requestAlwaysAuthorization];

在第一次執行時,必須出現一個彈出窗口,以允許使用當前用戶的職位。 允許使用當前位置后,使用以下命令啟動LocationManager:

[LocationManager startUpdatingLocation];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM