如何让app多个页面只用一个地图实例

地图唯一实例,放置不同地图页面切换,地图页面和非地图页面来回切换导致内存持续上涨问题。
声明
//对外开放全局变量,获取高德地图唯一实例指针
//由于高德地图只能初始化一次,重复释放后初始化会出现内存不能正常释放的情况,所以使用全局高德地图指针
//由于ARC机制是若有有一个地方应用,就不会把对象释放了掉,所以全局百度地图指针能保证高德地图的唯一实例不会被释放掉。
//使用高德地图的地方全部通过该函数引用获取唯一实例
//若获取到后先判断是否为空(初始化过),若为空直接初化它,若非空把该对象强制转化为MAMapView *类型的指针,调整frame,设置代理就可以使用了
//由于非高德地图的代理对象不允许定义MAMapView类的对象指针,所以用它的基类(UIView *)指向它。
//高德地图基类指针专用
@property(nonatomic,strong) UIView *mymapView;

pragma mark MAMap

-(UIView *)getMAMapViewInstance;
-(void)setMAMapViewInstance : (UIView *)mymapView;

实现
-(UIView *)getMAMapViewInstance
{
FLDDLogDebug(@”函数”);
return self.mymapView;
}

-(void)setMAMapViewInstance : (UIView *)mymapView
{
FLDDLogDebug(@”函数”);
if(nil == self.mymapView)
{
self.mymapView = mymapView;
}
}

3D地图中的使用
MAMapView namapView = (MAMapView )([[Singleton sharedInstance] getMAMapViewInstance]);
if(nil == namapView)
{
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kControlWidth, kControlHeight)];
[[Singleton sharedInstance] setMAMapViewInstance:_mapView];
}
else
{
CGRect newRect = CGRectMake(0, 0, kControlWidth, kControlHeight);
namapView.frame = newRect;
_mapView = namapView;
}

_mapView.delegate = self;
[self.view addSubview:_mapView];

// //定位
_mapView.showsUserLocation = YES;
//地图跟着位置和方向移动
[_mapView setUserTrackingMode:MAUserTrackingModeFollow animated:YES];

_mapView.showsCompass = NO;
//楼块隐藏
_mapView.buildingsDisabled=YES;
//后台定位 可持久记录位置信息。
_mapView.pausesLocationUpdatesAutomatically = NO;
//不能旋转
_mapView.rotateEnabled=NO;
_mapView.distanceFilter = DISTANCE_FILTER;

// _mapView.desiredAccuracy = kCLLocationAccuracyHundredMeters;
// mapView.showsScale = YES;
// [mapView setZoomLevel:KmaxLEVEL animated:NO];
//自定义精度圈样式 去除精度圈
_mapView.delegate = self;

热力图中的使用
MAMapView namapView = (MAMapView )([[Singleton sharedInstance] getMAMapViewInstance]);
if(nil == namapView)
{
namapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kControlWidth, kControlHeight)];
[[Singleton sharedInstance] setMAMapViewInstance:namapView];
self.mapView = namapView;
}
else
{
namapView.frame = self.view.bounds;
self.mapView = namapView;
}

_mapView.delegate = self;
_mapView.showsUserLocation = YES;
_mapView.showsUserLocation = YES;

导航中的使用
FLDDLogDebug(@”函数”);
self.mapView = (MAMapView *)[[Singleton sharedInstance] getMAMapViewInstance];
if(nil == _mapView)
{
_mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, kControlWidth, kControlHeight)];
[[Singleton sharedInstance] setMAMapViewInstance:_mapView];
}
else
{
self.mapView.frame = self.view.bounds;
}
_mapView.delegate = self;
_mapView.showsUserLocation = YES;
[self.view addSubview:self.mapView];

高德地图终于支持多实例了,不用这种曲线救国的方式实现多实例了。
废除:// self.naviViewController = [[AMapNaviViewController alloc] initWithMapView:mymapView delegate:self];
采用新的代理函数:
self.naviViewController = [[AMapNaviViewController alloc] initWithDelegate:self];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值