searchGeocode method

Future<List<Geocode>> searchGeocode (String keyword, { String city: '' })

地理编码(地址转坐标)

输入关键字keyword, 并且限制所在城市city

Implementation

static Future<List<Geocode>> searchGeocode(
  String keyword, {
  String city = '',
}) async {
  // 会在listener中关闭
  // ignore: close_sinks
  final _controller = StreamController<List<Geocode>>();

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

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

      // 创建搜索对象
      _androidGeocodeSearch = await ObjectFactory_Android
          .createcom_amap_api_services_geocoder_GeocodeSearch__android_content_Context(
              context);

      // 设置回调
      await _androidGeocodeSearch
          .setOnGeocodeSearchListener(_AndroidSearchListener(_controller));

      // 开始搜索
      await _androidGeocodeSearch.getFromLocationNameAsyn(query);

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

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

      // 创建搜索请求
      final request =
          await ObjectFactory_iOS.createAMapGeocodeSearchRequest();
      // 设置关键字
      await request.set_address(keyword);
      // 设置城市
      await request.set_city(city);

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

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