Appearance
地理编码(Geocoding)
1 逆地理(坐标 → 地址)
调用
java
mapClient.getGeocodingService().reverseGeocodeAPI(
reverseParams, // GeoParams.create().setLocation("lng,lat")
new RpcRequestUtils.Callback<ReverseGeoResponse>() { /* 回调同你现有写法 */ }
);响应结构(ReverseGeoResponse)
| 字段路径 | 类型 | 可空 | 单位/取值 | 说明 | 服务端字段 |
|---|---|---|---|---|---|
| status | int | 否 | — | 业务状态码,10000 成功 | status |
| msg | string | 是 | — | 文本提示 | msg |
| traceId | string | 是 | — | TraceId | trace_id |
| results | array<object> | 是 | — | 结果列表 | results |
| results[].name | string | 是 | — | 地点/兴趣点名 | name |
| results[].address | string | 是 | — | 地址(备用) | address |
| results[].addressAll | string | 是 | — | 完整地址(展示优先) | address_all |
| results[].province | string | 是 | — | 省 | province |
| results[].city | string | 是 | — | 市 | city |
| results[].district | string | 是 | — | 区/县 | district |
| results[].adcode | string | 是 | — | 行政编码 | adcode |
| results[].location | object | 是 | — | 坐标对象(经度在前) | location |
| results[].location.lng | double | 是 | — | 经度 | lng |
| results[].location.lat | double | 是 | — | 纬度 | 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)
| 字段路径 | 类型 | 可空 | 单位/取值 | 说明 | 服务端字段 |
|---|---|---|---|---|---|
| status | int | 否 | — | 10000 成功 | status |
| msg | string | 是 | — | 文本提示 | msg |
| traceId | string | 是 | — | TraceId | trace_id |
| results | object | 是 | — | 结果容器 | results |
| results.count | int | 是 | — | 命中条数 | count |
| results.geocodes | array<object> | 是 | — | 候选列表 | geocodes |
| results.geocodes[].country | string | 是 | — | 国家 | country |
| results.geocodes[].province | string | 是 | — | 省 | province |
| results.geocodes[].city | string | 是 | — | 市 | city |
| results.geocodes[].district | string | 是 | — | 区/县 | district |
| results.geocodes[].adcode | string | 是 | — | 行政编码 | adcode |
| results.geocodes[].location | object | 是 | — | 坐标对象(经度在前) | location |
| results.geocodes[].location.lng | double | 是 | — | 经度 | lng |
| results.geocodes[].location.lat | double | 是 | — | 纬度 | 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);
}