searchKeyword method

Future<List<Poi>> searchKeyword (String keyword, { String city: '' })

关键字搜索poi

在城市city搜索关键字keyword的poi

Implementation

static Future<List<Poi>> searchKeyword(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);

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

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

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

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

      // 创建请求对象
      final request =
          await ObjectFactory_iOS.createAMapPOIKeywordsSearchRequest();
      // 设置关键字
      await request.set_keywords(keyword);
      // 设置城市
      await request.set_city(city);

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

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