geocode method

Future<GeocodeResponse> geocode(
  1. String address, {
  2. String? city,
  3. String? output,
})

地理编码 address: 结构化地址信息 city: 指定查询的城市,默认全国范围 output: 返回数据格式类型,默认为JSON

Implementation

Future<GeocodeResponse> geocode(
  String address, {
  String? city,
  String? output,
}) async {
  Uri uri = appendApiPath(this.uri, "/v3/geocode/geo");
  final params = <String, dynamic>{};
  params['key'] = apiKey;
  params["address"] = address;
  if (city != null && city.isNotEmpty) params["city"] = city;
  if (output != null && output.isNotEmpty) params["output"] = output;
  if (secretKey != null) params["sig"] = generateSignature(params);
  final url = appendParameters(uri, params).toString();
  final response = await doGet(url, headers: apiHeaders);
  return GeocodeResponse.fromJson(jsonDecode(response.body));
}