百度地图
- 获取秘钥
- 配置开发环境
使用cocoapods自动配置
pod 'BaiduMapKit' #百度地图SDK - 注意事项
- HelloBaiduMap
基础地图
#pragma mark - 基础地图常用功能
//设置地图类型
_mapView.mapType = BMKMapTypeNone;//设置地图为空白类型
//切换为卫星图
[_mapView setMapType:BMKMapTypeSatellite];
//切换为普通地图
[_mapView setMapType:BMKMapTypeStandard];
//打开实时路况图层
[_mapView setTrafficEnabled:YES];
//打开百度城市热力图图层(百度自有数据)
[_mapView setBaiduHeatMapEnabled:YES];
//关闭百度城市热力图图层(百度自有数据)
[_mapView setBaiduHeatMapEnabled:NO];
//logo位置
_mapView.logoPosition = BMKLogoPositionCenterTop;
// 添加一个PointAnnotation
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
CLLocationCoordinate2D coor;
coor.latitude = 39.915;
coor.longitude = 116.404;
annotation.coordinate = coor;
annotation.title = @"这里是北京";
[_mapView addAnnotation:annotation];
#pragma mark - 动画效果
// Override
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotation"];
newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示
return newAnnotationView;
}
return nil;
}
室内地图
//打开室内图
_mapView.baseIndoorMapEnabled = YES;
//设置地图大小
_mapView.zoomLevel = 15;
POI检索
POI检索,需要在鉴权之后
BMKPoiSearch *_searcher;
//---------------------------------------------------------------
//延迟检索
[self performSelector:@selector(searchPOI) withObject:nil afterDelay:2.0];
//---------------------------------------------------------------
-(void)searchPOI {
//初始化检索对象
_searcher =[[BMKPoiSearch alloc]init];
_searcher.delegate = self;
//发起检索
BMKNearbySearchOption *option = [[BMKNearbySearchOption alloc]init];
option.pageIndex = 0;
option.pageCapacity = 10;
option.location = CLLocationCoordinate2DMake(39.915, 116.404);
option.keyword = @"小吃";
BOOL flag = [_searcher poiSearchNearBy:option];
if(flag)
{
NSLog(@"周边检索发送成功");
}
else
{
NSLog(@"周边检索发送失败");
}
}
#pragma mark - BMKPoiSearchDelegate
//实现PoiSearchDeleage处理回调结果
- (void)onGetPoiResult:(BMKPoiSearch*)searcher result:(BMKPoiResult*)poiResultList errorCode:(BMKSearchErrorCode)error
{
if (error == BMK_SEARCH_NO_ERROR) {
//在此处理正常结果
for (BMKPoiInfo *poiInfo in poiResultList.poiInfoList) {
// 添加一个PointAnnotation
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
annotation.coordinate = poiInfo.pt;
annotation.title = poiInfo.name;
[_mapView addAnnotation:annotation];
}
}
else if (error == BMK_SEARCH_AMBIGUOUS_KEYWORD){
//当在设置城市未找到结果,但在其他城市找到结果时,回调建议检索城市列表
// result.cityList;
NSLog(@"起始点有歧义");
} else {
NSLog(@"抱歉,未找到结果");
NSLog(@"%d",error);
}
}