iOS开发之高德地图

初始化

//初始化地图

-(void)InitSubViewMapView

{

    /*创建地图*/

    self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenHeight-IPHONEX_SAFE_BOTTOM_MARGIN)];

    self.mapView.delegate=self;

    ///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码

    self.mapView.showsUserLocation = YES;

    self.mapView.userTrackingMode = MAUserTrackingModeFollow;

    //是否显示指南针

    self.mapView.showsCompass=NO;

    //设置缩放范围

    [self.mapView setZoomLevel:18 animated:YES];

    //自定义地图

    NSString *path1 = [NSString stringWithFormat:@"%@/style_extra.data", [NSBundle mainBundle].bundlePath];

    NSString *path2 = [NSString stringWithFormat:@"%@/style.data", [NSBundle mainBundle].bundlePath];

    NSData *data1 = [NSData dataWithContentsOfFile:path1];

    NSData *data2 = [NSData dataWithContentsOfFile:path2];

    MAMapCustomStyleOptions *options = [[MAMapCustomStyleOptions alloc] init];

    options.styleData= data2;

    options.styleExtraData= data1;

    [self.mapView setCustomMapStyleOptions:options];

    [self.mapView setCustomMapStyleEnabled:YES];

    [self.view addSubview:self.mapView];

}

不需要用到的时候记得销毁 

- (void)viewWillAppear:(BOOL)animated{


    [superviewWillAppear:animated];


    _mapView.showsUserLocation = YES;

    _mapView.delegate=self;

}

-(void)viewWillDisappear:(BOOL)animated

{

    [superviewWillDisappear:animated];


    _mapView.showsUserLocation = NO;

    _mapView.delegate=nil;

}

地图拖动时会出现延迟的现象

方法1:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

{

     [self applyMapViewMemoryRelease];

}

- (void)applyMapViewMemoryRelease{

    MKMapType _type = _mapView.mapType;

    switch(_mapView.mapType) {

        case MKMapTypeHybrid:

        {

            _mapView.mapType = MKMapTypeStandard;

        }

            break;

        case MKMapTypeStandard:

        {

            _mapView.mapType = MKMapTypeHybrid;

        }

            break;

        default:

            break;

    }

    _mapView.mapType= _type;

}

但这样滑动显示区域时会有闪烁

方法2:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

{

    [self.mapView removeFromSuperview];

    [self.viewaddSubview:mapView];

}

这样可以有效改善内存暴涨的问题

你可能感兴趣的:(iOS开发之高德地图)