室内高精度定位
功能场景
本示例展示了在百度地图室内图覆盖的场所中如何获取精准的室内定位信息。
//mapopen-website-wiki.bj.bcebos.com/demos/室内定位.mp4
setIndoorEnable(boolean enabled)
设置是否显示室内图, 默认室内图不显示 室内图只有在缩放级别[17, 22]范围才生效,但是在18级之上(包含18级)才会有楼层边条显示。
setOnBaseIndoorMapListener(BaiduMap.OnBaseIndoorMapListener listener)
onBaseIndoorMapMode(boolean in, MapBaseIndoorMapInfo info)
地图进入室内图模式回调函数,in:是否进入室内图模式,info :室内图信息
打开室内定位模式,该模式下会加快定位速度并输出连续室内定位结果;当BDLocation.getFloor()!= null时,表明该区域已经支持室内定位,开发者可以尝试调用该接口,体验高精度室内定位功能
BDAbstractLocationListener
BaiduMap.OnBaseIndoorMapListener onBaseIndoorMapListener = new BaiduMap.OnBaseIndoorMapListener() {
@Override
public void onBaseIndoorMapMode(boolean b, MapBaseIndoorMapInfo mapBaseIndoorMapInfo) {
// 设置楼层数据
mFloorListAdapter.setmFloorList(mapBaseIndoorMapInfo.getFloors());
mStripListView.setVisibility(View.VISIBLE);
mStripListView.setStripAdapter(mFloorListAdapter);
mMapBaseIndoorMapInfo = mapBaseIndoorMapInfo;
}
};
复制成功
mBaiduMap = mMapView.getMap();
// 设置是否显示室内图, 默认室内图不显示
mBaiduMap.setIndoorEnable(true);
// 设置室内图模式监听
mBaiduMap.setOnBaseIndoorMapListener(onBaseIndoorMapListener);
复制成功
/**
* 定位SDK监听函数
*/
public class MyLocationListenner extends BDAbstractLocationListener {
private String lastFloor = null;
@Override
public void onReceiveLocation(BDLocation location) {
// map view 销毁后不在处理新接收的位置
if (location == null || mMapView == null) {
return;
}
String bid = location.getBuildingID();
if (bid!= null && mMapBaseIndoorMapInfo!= null) {
// 校验是否满足室内定位模式开启条件
if (bid.equals(mMapBaseIndoorMapInfo.getID())) {
// 楼层
String floor = location.getFloor().toUpperCase();
boolean needUpdateFloor = true;
if (lastFloor == null) {
lastFloor = floor;
} else {
if (lastFloor.equals(floor)) {
needUpdateFloor = false;
} else {
lastFloor = floor;
}
}
if (needUpdateFloor) {
// 切换楼层
mBaiduMap.switchBaseIndoorMapFloor(floor, mMapBaseIndoorMapInfo.getID());
mFloorListAdapter.setSelectedPostion(mFloorListAdapter.getPosition(floor));
mFloorListAdapter.notifyDataSetInvalidated();
}
if (!location.isIndoorLocMode()) {
// 开启室内定位模式,只有支持室内定位功能的定位SDK版本才能调用该接口
mLocationClient.startIndoorMode();
}
}
}
复制成功
//mapopen-website-wiki.bj.bcebos.com/demos/iostest.MP4
- (void)clearClusterItems;
- (NSArray<BMKCluster *> *)getClusters:(CGFloat)zoomLevel;
1.第一步
1
/** 更新标注展示. */
- (void)updateClusters {
_clusterZoom = (NSInteger)_mapView.zoomLevel;
@synchronized(_clusterManager.clusterCaches) {
NSMutableArray *clusters = [_clusterManager.clusterCaches objectAtIndex:(_clusterZoom - 3)];
if (clusters.count > 0) {
// 移除一组标注
[_mapView removeAnnotations:_mapView.annotations];
//将一组标注添加到当前地图View中
[_mapView addAnnotations:clusters];
} else {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 获取聚合后的标注
__block NSArray *array = [weakSelf.clusterManager getClusters:weakSelf.clusterZoom];
dispatch_async(dispatch_get_main_queue(), ^{
for (BMKCluster *item in array) {
ClusterAnnotation *annotation = [[ClusterAnnotation alloc] init];
// 设置标注的经纬度坐标
annotation.coordinate = item.coordinate;
annotation.size = item.size;
// 设置标注的标题
annotation.title = [NSString stringWithFormat:@"我是%lu个", (unsigned long)item.size];
[clusters addObject:annotation];
}
// 移除一组标注
[weakSelf.mapView removeAnnotations:weakSelf.mapView.annotations];
// 将一组标注添加到当前地图View中
[weakSelf.mapView addAnnotations:clusters];
});
});
}
}
}
复制成功
2.第二步
2
/** 更新标注展示. */
- (void)updateClusters {
_clusterZoom = (NSInteger)_mapView.zoomLevel;
@synchronized(_clusterManager.clusterCaches) {
NSMutableArray *clusters = [_clusterManager.clusterCaches objectAtIndex:(_clusterZoom - 3)];
if (clusters.count > 0) {
// 移除一组标注
[_mapView removeAnnotations:_mapView.annotations];
//将一组标注添加到当前地图View中
[_mapView addAnnotations:clusters];
} else {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 获取聚合后的标注
__block NSArray *array = [weakSelf.clusterManager getClusters:weakSelf.clusterZoom];
dispatch_async(dispatch_get_main_queue(), ^{
for (BMKCluster *item in array) {
ClusterAnnotation *annotation = [[ClusterAnnotation alloc] init];
// 设置标注的经纬度坐标
annotation.coordinate = item.coordinate;
annotation.size = item.size;
// 设置标注的标题
annotation.title = [NSString stringWithFormat:@"我是%lu个", (unsigned long)item.size];
[clusters addObject:annotation];
}
// 移除一组标注
[weakSelf.mapView removeAnnotations:weakSelf.mapView.annotations];
// 将一组标注添加到当前地图View中
[weakSelf.mapView addAnnotations:clusters];
});
});
}
}
}
复制成功
3.名字
3
/** 更新标注展示. */
- (void)updateClusters {
_clusterZoom = (NSInteger)_mapView.zoomLevel;
@synchronized(_clusterManager.clusterCaches) {
NSMutableArray *clusters = [_clusterManager.clusterCaches objectAtIndex:(_clusterZoom - 3)];
if (clusters.count > 0) {
// 移除一组标注
[_mapView removeAnnotations:_mapView.annotations];
//将一组标注添加到当前地图View中
[_mapView addAnnotations:clusters];
} else {
__weak typeof(self) weakSelf = self;
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 获取聚合后的标注
__block NSArray *array = [weakSelf.clusterManager getClusters:weakSelf.clusterZoom];
dispatch_async(dispatch_get_main_queue(), ^{
for (BMKCluster *item in array) {
ClusterAnnotation *annotation = [[ClusterAnnotation alloc] init];
// 设置标注的经纬度坐标
annotation.coordinate = item.coordinate;
annotation.size = item.size;
// 设置标注的标题
annotation.title = [NSString stringWithFormat:@"我是%lu个", (unsigned long)item.size];
[clusters addObject:annotation];
}
// 移除一组标注
[weakSelf.mapView removeAnnotations:weakSelf.mapView.annotations];
// 将一组标注添加到当前地图View中
[weakSelf.mapView addAnnotations:clusters];
});
});
}
}
}
复制成功