目录

Reverse Geocoding

Function

Obtains information about a place based on its longitude and latitude.

Restrictions

A maximum of 11 records can be returned.

Prototype

Protocol

HTTPS POST

Direction

Your server -> Map Kit server

URL

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

NOTE:
  1. For details about API KEY, please refer to Obtaining the API Key.
  2. You can use the API key in either of the following ways:

    2.1 Concatenating it into the URL: Call the URLEncoder.encode("Your API key", "UTF-8") method to encode the API key using encodeURI. For example, if the original API key is ABC/DFG+, the conversion result is ABC%2FDFG%2B.

    2.2 Placing it in the header: Refer to the Authorization field in Request Header. This way is recommended.

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Request Parameters

Request Header

Parameter

Mandatory

Type

Description

Authorization

Yes

String

Service signature, which is used for authentication. The value is in Bearer+Space+API key format.

Example: Bearer ABC/DFG+

Content-Type

Yes

application/json

Data format of a request.

Request Body

Parameter

Mandatory

Type

Description

location

Yes

Coordinate

Longitude and latitude.

language

No

String(<=16)

Language in which search results are displayed. For details, please refer to Supported Languages. If this parameter is not passed, the local language will be used.

politicalView

No

String(=2)

Political view. The value is a two-letter country/region code complying with ISO 3166-1 alpha-2.

CAUTION:

This parameter has been deprecated.

radius

No

int

Radius of a region where POIs and addresses are searched for reverse geocoding, in meters. The value ranges from 0 to 50.

returnPoi

No

boolean

Indicates whether to return a POI. The default value is true.

Request Example

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
}

Response Parameters

When the status code is 200:

Response Header

Parameter

Mandatory

Type

Description

Content-Type

Yes

application/json

Data format of a response.

Response Body

Parameter

Type

Description

returnCode

String

Result code. For details, please refer to Result Codes.

returnDesc

String

Result description.

sites

Site[]

Search result returned upon a successful search. If no record is found, an empty array will be returned.

NOTE:

If the value of returnPoi is false, the Poi attribute in the Site object will not be returned.

Response Example

When the status code is 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"
}

Call Example

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());
            }
        });
    }
}