searchReGeocode method

Future<ReGeocode> searchReGeocode (LatLng latLng, { double radius: 200.0 })

逆地理编码(坐标转地址)

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

Implementation

static Future<ReGeocode> searchReGeocode(
  LatLng latLng, {
  double radius = 200.0,
}) async {
  // 会在listener中关闭
  // ignore: close_sinks
  final _controller = StreamController<ReGeocode>(sync: true);

  platform(
    android: (pool) async {
      // 创建中心点
      final latLngPoint = await ObjectFactory_Android
          .createcom_amap_api_services_core_LatLonPoint__double__double(
              latLng.latitude, latLng.longitude);

      // 创建查询对象
      final query = await ObjectFactory_Android
          .createcom_amap_api_services_geocoder_RegeocodeQuery__com_amap_api_services_core_LatLonPoint__float__String(
              latLngPoint, radius, 'AMAP');

      // 获取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.getFromLocationAsyn(query);

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

      // 创建中心点
      final amapLocation = await ObjectFactory_iOS.createAMapGeoPoint();
      await amapLocation.set_latitude(latLng.latitude);
      await amapLocation.set_longitude(latLng.longitude);

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

      // 创建搜索请求
      final request =
          await ObjectFactory_iOS.createAMapReGeocodeSearchRequest();
      // 设置中心点
      await request.set_location(amapLocation);
      // 设置半径
      await request.set_radius(radius.toInt());

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

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