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;
}