searchAround method

Future<List<Poi>> searchAround (LatLng center, { String keyword: '', String city: '' })

周边搜索poi

在中心点center周边搜索关键字keyword和城市city的poi

Implementation

static Future<List<Poi>> searchAround(
  LatLng center, {
  String keyword = '',
  String city = '',
}) {
  // 会在listener中关闭
  // ignore: close_sinks
  final _controller = StreamController<List<Poi>>(sync: true);

  platform(
    android: (pool) async {
      // 创建查询对象
      final query = await ObjectFactory_Android
          .createcom_amap_api_services_poisearch_PoiSearch_Query__String__String__String(
              keyword, '', city);

      // 获取android上下文
      final context = await ObjectFactory_Android.getandroid_app_Activity();

      // 创建搜索对象
      _androidPoiSearch = await ObjectFactory_Android
          .createcom_amap_api_services_poisearch_PoiSearch__android_content_Context__com_amap_api_services_poisearch_PoiSearch_Query(
              context, query);

      // 创建中心点
      final centerLatLng = await ObjectFactory_Android
          .createcom_amap_api_services_core_LatLonPoint__double__double(
              center.latitude, center.longitude);
      // 创建边界
      final bound = await ObjectFactory_Android
          .createcom_amap_api_services_poisearch_PoiSearch_SearchBound__com_amap_api_services_core_LatLonPoint__int(
              centerLatLng, 1000);
      await _androidPoiSearch.setBound(bound);

      // 设置回调
      await _androidPoiSearch
          .setOnPoiSearchListener(_AndroidSearchListener(_controller));

      // 开始搜索
      await _androidPoiSearch.searchPOIAsyn();

      // 局部变量从HEAP中解除引用
      pool..add(query)..add(centerLatLng)..add(bound);
    },
    ios: (pool) async {
      _iosSearch = await ObjectFactory_iOS.createAMapSearchAPI();

      // 设置回调
      await _iosSearch.set_delegate(_IOSSearchListener(_controller));

      // 创建周边搜索请求
      final request =
          await ObjectFactory_iOS.createAMapPOIAroundSearchRequest();
      // 设置关键字
      await request.set_keywords(keyword);
      // 设置城市
      await request.set_city(city);
      // 创建中心点
      final location = await ObjectFactory_iOS.createAMapGeoPoint();
      await location.set_latitude(center.latitude);
      await location.set_longitude(center.longitude);
      await request.set_location(location);

      // 开始搜索
      await _iosSearch.AMapPOIAroundSearch(request);

      // 局部变量从HEAP中解除引用
      pool..add(request)..add(location);
    },
  );
  return _controller.stream.first;
}