目录

逆地理编码

功能介绍

获取经纬度对应的地点信息。

使用约束

最多返回11条记录。

接口原型

承载协议

HTTPS POST

接口方向

开发者 -> 华为地图服务器

接口URL

https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode?key=API KEY

说明:
  1. 获取API KEY的方式请参见获取API密钥。
  2. API秘钥使用有2种方式:

    2.1 拼接URL中:使用“API密钥”时需要调用URLEncoder.encode("Your apiKey", "UTF-8")方法对API密钥进行encodeURI编码。例如,原始API密钥:ABC/DFG+ ,转换结果:ABC%2FDFG%2B。

    2.2 放在Header内:参考Request Header中Authorization字段,推荐使用该方式。

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

请求参数

Request Header

参数

是否必选

参数类型

描述

Authorization

是

String

业务签名,用于认证鉴权,格式为:Bearer+空格+API Key。

示例:Bearer ABC/DFG+。

Content-Type

是

application/json

请求消息的数据格式。

Request Body

参数

是否必选

参数类型

描述

location

是

Coordinate

经纬度。

language

否

String(<=16)

搜索结果返回的语言,语种取值请参见支持的语言列表。如果不传,返回地点的当地语言。

politicalView

否

String(=2)

政治观点,采用ISO 3166-1 alpha-2规范的2位国家/地区码。

注意:

该参数已废弃。

radius

否

int

POI、门址召回范围半径,单位:米 。取值范围:[0, 50]。

returnPoi

否

boolean

是否返回POI,默认为true。

请求示例

POST https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode?key=API KEY   HTTP/1.1  
Content-Type: application/json  
Accept: application/json
{
    "location": {
        "lng": 10.252502,
        "lat": 43.8739168
    },
    "language": "en",
    "radius": 10
}

响应参数

状态码为200时:

Response Header

参数

是否必选

参数类型

描述

Content-Type

是

application/json

响应消息的数据格式。

Response Body

参数名称

参数类型

描述

returnCode

String

返回码,具体请参见错误码。

returnDesc

String

返回值描述。

sites

Site[]

如果查询成功,返回搜索结果。如果没有结果,返回空数组。

说明:

如果returnPoi是false,不返回Site的Poi对象。

响应示例

状态码为200时:

HTTP/1.1 200 OK
Content-type: application/json
{
    "returnCode": "0",
    "sites": [
        {
            "formatAddress": "Tuscany, Italy",
            "address": {
                "country": "Italy",
                "city": "Viareggio",
                "countryCode": "IT",
                "tertiaryAdminArea": "Viareggio",
                "postalCode": "55049",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca"
            },
            "aoiFlag": true,
            "poi": {
                "rating": 0.0,
                "poiTypes": [
                    "POSTAL_CODE"
                ],
                "childrenNodes": [],
                "hwPoiTypes": [
                    "POSTAL_CODE"
                ],
                "internationalPhone": ""
            },
            "viewport": {
                "southwest": {
                    "lng": 10.2276414,
                    "lat": 43.8156941
                },
                "northeast": {
                    "lng": 10.3116972,
                    "lat": 43.8968399
                }
            },
            "name": "55049",
            "siteId": "552976400316381312",
            "location": {
                "lng": 10.2568888,
                "lat": 43.874537
            }
        },
        {
            "formatAddress": "Italy",
            "address": {
                "country": "Italy",
                "city": "Viareggio",
                "countryCode": "IT",
                "tertiaryAdminArea": "Viareggio",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca"
            },
            "aoiFlag": false,
            "poi": {
                "rating": 0.0,
                "poiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_3"
                ],
                "childrenNodes": [],
                "hwPoiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_3"
                ],
                "internationalPhone": ""
            },
            "viewport": {
                "southwest": {
                    "lng": 10.2276414,
                    "lat": 43.8156941
                },
                "northeast": {
                    "lng": 10.3116972,
                    "lat": 43.8968399
                }
            },
            "name": "Viareggio",
            "siteId": "547123016540315451",
            "location": {
                "lng": 10.2568888,
                "lat": 43.874537
            }
        },
        {
            "formatAddress": "Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca"
            },
            "aoiFlag": false,
            "poi": {
                "rating": 0.0,
                "poiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_2"
                ],
                "childrenNodes": [],
                "hwPoiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_2"
                ],
                "internationalPhone": ""
            },
            "viewport": {
                "southwest": {
                    "lng": 10.1432268,
                    "lat": 43.7497847
                },
                "northeast": {
                    "lng": 10.7378322,
                    "lat": 44.2862267
                }
            },
            "name": "Lucca",
            "siteId": "387253859151030327",
            "location": {
                "lng": 10.507994,
                "lat": 43.8430139
            }
        },
        {
            "formatAddress": "Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "adminArea": "Tuscany"
            },
            "aoiFlag": false,
            "poi": {
                "rating": 0.0,
                "poiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_1"
                ],
                "childrenNodes": [],
                "hwPoiTypes": [
                    "ADMINISTRATIVE_AREA_LEVEL_1"
                ],
                "internationalPhone": ""
            },
            "viewport": {
                "southwest": {
                    "lng": 9.6867915,
                    "lat": 42.2376428
                },
                "northeast": {
                    "lng": 12.3723258,
                    "lat": 44.4725475
                }
            },
            "name": "Tuscany",
            "siteId": "59784159559947560",
            "location": {
                "lng": 11.21306161035054,
                "lat": 43.4167473
            }
        },
        {
            "formatAddress": "",
            "address": {
                "country": "Italy",
                "countryCode": "IT"
            },
            "aoiFlag": false,
            "poi": {
                "rating": 0.0,
                "poiTypes": [
                    "COUNTRY"
                ],
                "childrenNodes": [],
                "hwPoiTypes": [
                    "COUNTRY"
                ],
                "internationalPhone": ""
            },
            "viewport": {
                "southwest": {
                    "lng": 6.6266397,
                    "lat": 35.4928765
                },
                "northeast": {
                    "lng": 18.5203619,
                    "lat": 47.0924248
                }
            },
            "name": "Italy",
            "siteId": "243468147533395204",
            "location": {
                "lng": 12.68361340731412,
                "lat": 42.5040971
            }
        }
    ],
    "returnDesc": "OK"
}

调用示例

public class GeocodingService {
    public static final String ROOT_URL = "https://siteapi.cloud.huawei.com/mapApi/v1/siteService/reverseGeocode";

    public static final String connection = "?key=";

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");

    public static void reverseGeocoding(String apiKey) throws UnsupportedEncodingException {
        JSONObject json = new JSONObject();

        JSONObject location = new JSONObject();
        try {
            location.put("lng", 77.2155);
            location.put("lat", 18.0527);
            json.put("location", location);
            json.put("radius", 10);
        } catch (JSONException e) {
            Log.e("error", e.getMessage());
        }
        RequestBody body = RequestBody.create(JSON, String.valueOf(json));

        OkHttpClient client = new OkHttpClient();
        Request request =
            new Request.Builder().url(ROOT_URL + connection + URLEncoder.encode(apiKey, "UTF-8"))
                .post(body)
                .build();

        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.e("ReverseGeocoding", e.toString());
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("ReverseGeocoding", response.body().string());
            }
        });
    }
}