天天看點

iOS高德地圖 指南針(羅盤)不轉的解決方法

self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.frame))];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;

[self.view addSubview:self.mapView];

self.mapView.userTrackingMode = MAUserTrackingModeFollowWithHeading;(核心)

[self.mapView setCompassImage:[UIImage imageNamed:@"[email protected]"]];
           

或者

//地圖懶加載
- (MAMapView *)mapView{
       if (!_mapView) {
        _mapView =  [[MAMapView alloc] initWithFrame:CGRectMake(0, kH_SegmentOfCustomeHeight, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.frame) - kH_SegmentOfCustomeHeight)];

    _mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _mapView.delegate = self;
    _mapView.showsUserLocation = YES;    //YES 為打開定位,NO為關閉定位
//    _mapView.desiredAccuracy = kCLLocationAccuracyKilometer;
//    _mapView.distanceFilter = kCLLocationAccuracyKilometer;
//    _mapView.headingFilter  = 90;

    _mapView.zoomLevel = 14;
    //自定義定位經度圈樣式
    _mapView.customizeUserLocationAccuracyCircleRepresentation = YES;

          //地圖跟蹤模式
 //    _mapView.userTrackingMode = MAUserTrackingModeFollow;
     _mapView.userTrackingMode = MAUserTrackingModeFollowWithHeading;
     _mapView.showsCompass = YES;
     [_mapView setCompassImage:[UIImage imageNamed:@"[email protected]"]];

    //背景定位
    _mapView.pausesLocationUpdatesAutomatically = NO;
    _mapView.allowsBackgroundLocationUpdates = NO;//iOS9以上系統必須配置
    }
    return _mapView;
}