Skip to content

地理编码(Geocoding)

1 逆地理(坐标 → 地址)

调用

java
mapClient.getGeocodingService().reverseGeocodeAPI(
    reverseParams,   // GeoParams.create().setLocation("lng,lat")
    new RpcRequestUtils.Callback<ReverseGeoResponse>() { /* 回调同你现有写法 */ }
);

响应结构(ReverseGeoResponse)

字段路径类型可空单位/取值说明服务端字段
statusint业务状态码,10000 成功status
msgstring文本提示msg
traceIdstringTraceIdtrace_id
resultsarray<object>结果列表results
results[].namestring地点/兴趣点名name
results[].addressstring地址(备用)address
results[].addressAllstring完整地址(展示优先)address_all
results[].provincestringprovince
results[].citystringcity
results[].districtstring区/县district
results[].adcodestring行政编码adcode
results[].locationobject坐标对象(经度在前)location
results[].location.lngdouble经度lng
results[].location.latdouble纬度lat

读取示例(取Top1)

java
ReverseGeoResponse rev = data;
if (rev != null && rev.results != null && !rev.results.isEmpty()) {
  ReverseGeoResponse.Result r0 = rev.results.get(0);
  String addr = (r0.addressAll != null && !r0.addressAll.isEmpty()) ? r0.addressAll : r0.address;
  Double lng = (r0.location != null) ? r0.location.lng : null;
  Double lat = (r0.location != null) ? r0.location.lat : null;
  String line = "逆地理Top1: " + r0.name
              + " | 地址=" + stringOrDash(addr)
              + " | 城市/区=" + stringOrDash(r0.city) + "/" + stringOrDash(r0.district)
              + " | adcode=" + stringOrDash(r0.adcode)
              + " | 坐标=" + stringOrDash(lng) + "," + stringOrDash(lat);
  // tv.setText(line);
}

2 正向地理(地址 → 坐标)

调用

java
mapClient.getGeocodingService().forwardGeocodeAPI(
    forwardParams,   // GeoParams.create().setAddress("...").setCity("城市")
    new RpcRequestUtils.Callback<ForwardGeoResponse>() { /* 回调同你现有写法 */ }
);

响应结构(ForwardGeoResponse)

字段路径类型可空单位/取值说明服务端字段
statusint10000 成功status
msgstring文本提示msg
traceIdstringTraceIdtrace_id
resultsobject结果容器results
results.countint命中条数count
results.geocodesarray<object>候选列表geocodes
results.geocodes[].countrystring国家country
results.geocodes[].provincestringprovince
results.geocodes[].citystringcity
results.geocodes[].districtstring区/县district
results.geocodes[].adcodestring行政编码adcode
results.geocodes[].locationobject坐标对象(经度在前)location
results.geocodes[].location.lngdouble经度lng
results.geocodes[].location.latdouble纬度lat

读取示例(Top1)

java
ForwardGeoResponse fwd = data;
if (fwd != null && fwd.results != null && fwd.results.geocodes != null && !fwd.results.geocodes.isEmpty()) {
  ForwardGeoResponse.GeoItem g = fwd.results.geocodes.get(0);
  Double lng = (g.location != null) ? g.location.lng : null;
  Double lat = (g.location != null) ? g.location.lat : null;
  String region = stringOrDash(g.province) + "/" + stringOrDash(g.city) + "/" + stringOrDash(g.district);
  String line = "正向地理Top1: 坐标=" + stringOrDash(lng) + "," + stringOrDash(lat)
              + " | 行政区=" + region + " | adcode=" + stringOrDash(g.adcode);
  // tv.setText(line);
}