//
// HYBBaiduMapHelper.m
// BaiduMapDemo
//
// Created by 黄仪标 on 14/11/18.
// Copyright (c) 2014年 黄仪标. All rights reserved.
//
#import "HYBBaiduMapHelper.h"
@interface HYBBaiduMapHelper ()
BMKGeneralDelegate,
BMKMapViewDelegate,
BMKRouteSearchDelegate> {
BMKMapManager *_mapManager;
HYBUserLocationCompletion _locationCompletion;
HYBRouteSearchCompletion _routeSearchCompletion;
BMKMapView *_mapView;
BMKLocationService *_locationService;
BMKRouteSearch *_routeSearch;
}
@end
@implementation HYBBaiduMapHelper
+ (HYBBaiduMapHelper *)shared {
static HYBBaiduMapHelper *baiduMapHelper =nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
if (!baiduMapHelper) {
baiduMapHelper = [[[selfclass]alloc]init];
}
});
return baiduMapHelper;
}
- (instancetype)init {
if (self = [superinit]) {
_mapManager = [[BMKMapManageralloc]init];
}
return self;
}
- (BOOL)startWithAppKey:(NSString *)appKey {
if (![appKeyisKindOfClass:[NSStringclass]] || appKey.length == 0 || appKey ==nil) {
return NO;
}
return [_mapManagerstart:appKeygeneralDelegate:self];
}
- (void)locateInView:(UIView *)mapSuerViewframe:(CGRect)framewithCompletion:(HYBUserLocationCompletion)completion {
_locationCompletion = [completioncopy];
[_locationServicestopUserLocationService];
_locationService =nil;
_locationService.delegate =nil;
_locationService = [[BMKLocationServicealloc]init];
[_locationServicestartUserLocationService];
if (_mapView) {
[_mapViewremoveFromSuperview];
_mapView =nil;
}
_mapView.delegate =nil;
_mapView.showsUserLocation = NO;
_mapView = [[BMKMapViewalloc]initWithFrame:frame];
[mapSuerViewaddSubview:_mapView];
_mapView.delegate = self;
// 先关闭显示的定位图层
_mapView.showsUserLocation = NO;
// 设置定位的状态
_mapView.userTrackingMode = BMKUserTrackingModeNone;
_mapView.showsUserLocation = YES;
return;
}
- (void)viewWillAppear {
[_mapViewviewWillAppear];
_mapView.delegate = self;
_locationService.delegate = self;
_routeSearch.delegate = self;
return;
}
- (void)viewWillDisappear {
[_mapViewviewWillDisappear];
_mapView.delegate =nil;
_locationService.delegate =nil;
_routeSearch.delegate =nil;
return;
}
- (void)viewDidDeallocOrReceiveMemoryWarning {