定位Flutter
功能场景
本示例介绍了如何快速集成百度定位Flutter插件,实现两端基本定位需求。
Flutter
iOS

//mapopen-website-wiki.bj.bcebos.com/demos/flutter.mp4

扫码体验
核心接口
类
接口
描述
void requestPermission()
定位权限动态申请
Future<bool> setApiKey(String key)
设置iOS端AK
void prepareLoc(Map androidMap, Map iosMap)
准备定位,配置Android端和iOS端定位参数
bdmap_location_flutter_plugin
void startLocation()
启动定位
void stopLocation()
void stopLocation()停止定位
Stream<Map<String, Object>> onResultCallback()
原生端以键值对map的形式回传定位结果到Flutter端
重点关注
详细配置和使用文档请参照

//mapopen-website-wiki.bj.bcebos.com/demos/iostest.MP4
扫码手机观看
核心代码
1.第一步
Objective-C
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.第二步
Objective-C
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.名字
Objective-C
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]; }); }); } } }
复制
深色
复制成功
更多功能
-
文档根本没法用
-
文档水平很差
-
文档水平一般
-
文档不错
-
文档写的很好