iOS8 高德地圖SDK MAMapView無法定位的問題,ios8mamapview
在iOS8的裝置上,使用高德地圖SDK你會發現MAMapView裡的回調位置是空的。
-(void)mapView:(MAMapView*)mapView didUpdateUserLocation:(MAUserLocation*)userLocation updatingLocation:(BOOL)updatingLocation{ CLLocation *currentLocation = userLocation.location; if (currentLocation) { }}
在iOS8上currentLocation是空的,導致定位失敗了。我們知道蘋果在iOS8上對定位進行了大幅度最佳化,可以支援室內地圖,常去地點統計,樓層等。
高德失敗的原因可能是未對iOS8做適配。
解決方案是:
1.工程的info.plist添加NSLocationWhenInUseDescription,NSLocationAlwaysUsageDescription欄位,不同的欄位對應的方法不同
2.在AppDelegate.m中聲明個CLLocationManager私人變數,代碼如下:
@interface AppDelegate()<CLLocationManagerDelegate>{ UINavigationController *_navController; CLLocationManager *_locationmanager;}@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [UIApplication sharedApplication].idleTimerDisabled = TRUE; _locationmanager = [[CLLocationManager alloc] init]; [_locationmanager requestAlwaysAuthorization]; //NSLocationAlwaysUsageDescription [_locationmanager requestWhenInUseAuthorization]; //NSLocationWhenInUseDescription _locationmanager.delegate = self;}
這樣在MAMapView的回調
-(void)mapView:(MAMapView*)mapView didUpdateUserLocation:(MAUserLocation*)userLocation updatingLocation:(BOOL)updatingLocation
就可以正常擷取使用者當前位置了,此時userLocation.location是有值的。
高德地圖為何經常不可以定位 gps
一般來說,GPS定位跟使用的地圖無關。另外,樓主所描述的在家幾十米偏差、一出門就沒有了的定位也不是GPS定位,而是移動通訊基站或WI-FI定位。
HTC的GPS首次定位往往需要時間長一些。需要在至少能看到三分之一半球天空(必須是天空,不能是窗戶外面的樓房)的地方,在靜止狀態下靜置3分鐘以上,甚至十幾分鐘,才有可能定位。如果想儘快定位,可以選中開啟輔助GPS(有的手機叫快速GPS),並開啟GPRS資料訪問,可以顯著縮短GPS搜星定位時間。
完成首次定位,以後再定位速度就快了。
您好我的9100使用Google地圖的時就是不可以定位,使用高德地圖雖然可以定位,但不準確,定位在5公裡,怎辦
手機GPS不能順利定位的原因太多,建議樓主安裝個GPS TEST測試一下,看看到底是搜不到星,還是能搜到星定不了位,把原因範圍縮小,以便找到針對性的解決辦法