目录

Place Search Suggestion

Function

Returns suggested places during user input, implementing search prediction.

Restrictions

A maximum of 5 records can be returned.

Prototype

Protocol

HTTPS POST

Direction

Your server -> Map Kit server

URL

https://siteapi.cloud.huawei.com/mapApi/v1/siteService/querySuggestion?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

query

Yes

String(<=512)

Search keyword.

location

No

Coordinate

Longitude and latitude to which search results need to be biased.

radius

No

int

Search radius, in meters. The value ranges from 1 to 50,000. The default value is 50000.

bounds

No

CoordinateBounds

Coordinate bounds to which search results need to be biased.

NOTE:

If both bounds and location are passed, the value of bounds takes precedence.

poiTypes

No

String[]

POI type of the returned place. The options are as follows:

  • GEOCODE: Returns only geocoding results but not company places. This value can be used to eliminate ambiguity in user input.
  • ADDRESS: Returns only geocoding results with accurate addresses. This value is recommended when a user searches for a complete address.
  • ESTABLISHMENT: Returns only company places.
  • REGIONS: Returns only places of the following types:
    • LOCALITY
    • SUBLOCALITY
    • POSTAL_CODE
    • COUNTRY
    • ADMINISTRATIVE_AREA_LEVEL_1
    • ADMINISTRATIVE_AREA_LEVEL_2
  • CITIES: Returns only results that match LOCALITY or ADMINISTRATIVE_AREA_LEVEL_3.

countryCode

No

String(=2)

Country/Region code, which complies with ISO 3166-1 alpha-2. This parameter is used to specify the country/region where places are searched.

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.

children

No

boolean

Indicates whether to return information about child nodes. The default value is false. If this parameter is set to true, IDs of child nodes will be returned.

Request Example

POST https://siteapi.cloud.huawei.com/mapApi/v1/siteService/querySuggestion?key=API KEY   HTTP/1.1  
Content-Type: application/json 
Accept: application/json 
{
    "query": "station",
    "location": {
        "lng": 10.252502,
        "lat": 43.8739168
    },
    "radius": 10000,
    "bounds": {
        "southwest": {
            "lng": 9.25073768878106,
            "lat": 42.87264496679441
        },
        "northeast": {
            "lng": 11.25426631121894,
            "lat": 44.875188633205596
        }
    },
    "poiTypes": [
        "GEOCODE",
        "ESTABLISHMENT"
    ],
    "countryCode": "IT",
    "language": "en",
    "children": true
}

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[]

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

Response Example

When the status code is 200:

HTTP/1.1 200 OK
Content-type: application/json
{
    "returnCode": "0",
    "sites": [
        {
            "formatAddress": "Via Del Fiaschetto, Camaiore, Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "tertiaryAdminArea": "Camaiore",
                "postalCode": "55041",
                "locality": "Camaiore",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca",
                "thoroughfare": "Via Del Fiaschetto"
            },
            "distance": 4270.603165446342,
            "poi": {
                "hwPoiTypes": [
                    "INTERCITY_RAILWAY_STATION"
                ],
                "comments": {
                    "commentInfo": {},
                    "starInfo": {
                        "averageRating": "0.0"
                    }
                },
                "rating": 0.0,
                "icon": "https://lfcontentcenterdev.hwcloudtest.cn/pub_1/HuaweiMaps_camp_0_9/ec/v3/vut4tpV7SaOciBZ2xc1yMw/Railway.png",
                "internationalPhone": "+39 892 021",
                "poiTypes": [
                    "TRAIN_STATION"
                ],
                "phone": "+39 892 021",
                "websiteUrl": "www.rfi.it",
                "childrenNodes": []
            },
            "name": "station Camaiore Lido-Capezzano",
            "prediction": {
                "matchedKeywords": [
                    {
                        "offset": 0,
                        "value": "station"
                    }
                ],
                "description": "station Camaiore Lido-Capezzano Via Del Fiaschetto, Camaiore, Italy",
                "matchedWords": [
                    {
                        "offset": 0,
                        "value": "station Camaiore Lido-Capezzano"
                    },
                    {
                        "offset": 32,
                        "value": "Via Del Fiaschetto"
                    },
                    {
                        "offset": 52,
                        "value": "Camaiore"
                    },
                    {
                        "offset": 62,
                        "value": "Italy"
                    }
                ]
            },
            "siteId": "252994930130698752",
            "location": {
                "lng": 10.2476061,
                "lat": 43.9121177
            }
        },
        {
            "formatAddress": "Piazza Massimo D'Azeglio, Viareggio, Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "tertiaryAdminArea": "Viareggio",
                "postalCode": "55049",
                "locality": "Viareggio",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca",
                "thoroughfare": "Piazza Massimo D'Azeglio"
            },
            "distance": 988.0220102959325,
            "poi": {
                "hwPoiTypes": [
                    "PETROL_STATION"
                ],
                "comments": {
                    "commentInfo": {},
                    "starInfo": {
                        "averageRating": "0.0"
                    }
                },
                "rating": 0.0,
                "icon": "https://lfcontentcenterdev.hwcloudtest.cn/pub_1/HuaweiMaps_camp_0_9/4/v3/7bwjt3bmRCaXa1R5icYriw/Petrol_Station.png",
                "internationalPhone": "",
                "poiTypes": [
                    "GAS_STATION"
                ],
                "phone": "",
                "websiteUrl": "www.ip.gruppoapi.com/",
                "childrenNodes": []
            },
            "name": "IP Station",
            "prediction": {
                "matchedKeywords": [
                    {
                        "offset": 3,
                        "value": "Station"
                    }
                ],
                "description": "IP Station Piazza Massimo D'Azeglio, Viareggio, Italy",
                "matchedWords": [
                    {
                        "offset": 0,
                        "value": "IP Station"
                    },
                    {
                        "offset": 11,
                        "value": "Piazza Massimo D'Azeglio"
                    },
                    {
                        "offset": 37,
                        "value": "Viareggio"
                    },
                    {
                        "offset": 48,
                        "value": "Italy"
                    }
                ]
            },
            "siteId": "653067455988646016",
            "location": {
                "lng": 10.244813,
                "lat": 43.866985
            }
        },
        {
            "formatAddress": "Via del Boccella, Massarosa, Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "tertiaryAdminArea": "Massarosa",
                "postalCode": "55054",
                "locality": "Massarosa",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca",
                "thoroughfare": "Via del Boccella"
            },
            "distance": 2563.662541588024,
            "poi": {
                "hwPoiTypes": [
                    "TRUCK_PARKING_AREA"
                ],
                "comments": {
                    "commentInfo": {},
                    "starInfo": {
                        "averageRating": "0.0"
                    }
                },
                "rating": 0.0,
                "icon": "https://lfcontentcenterdev.hwcloudtest.cn/pub_1/HuaweiMaps_camp_0_9/92/v3/DW3_8Uc4RNizAGBJ_a7WyA/Parking.png",
                "internationalPhone": "+39 0584 66932",
                "poiTypes": [
                    "PARKING"
                ],
                "phone": "+39 0584 66932",
                "childrenNodes": []
            },
            "name": "IP Station",
            "prediction": {
                "matchedKeywords": [
                    {
                        "offset": 3,
                        "value": "Station"
                    }
                ],
                "description": "IP Station Via del Boccella, Massarosa, Italy",
                "matchedWords": [
                    {
                        "offset": 0,
                        "value": "IP Station"
                    },
                    {
                        "offset": 11,
                        "value": "Via del Boccella"
                    },
                    {
                        "offset": 29,
                        "value": "Massarosa"
                    },
                    {
                        "offset": 40,
                        "value": "Italy"
                    }
                ]
            },
            "siteId": "853071390732332288",
            "location": {
                "lng": 10.2651025,
                "lat": 43.8950803
            }
        },
        {
            "formatAddress": "Via del Boccella, Massarosa, Italy",
            "address": {
                "country": "Italy",
                "countryCode": "IT",
                "tertiaryAdminArea": "Massarosa",
                "postalCode": "55054",
                "locality": "Massarosa",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca",
                "thoroughfare": "Via del Boccella"
            },
            "distance": 2563.718329470128,
            "poi": {
                "hwPoiTypes": [
                    "PETROL_STATION"
                ],
                "comments": {
                    "commentInfo": {},
                    "starInfo": {
                        "averageRating": "0.0"
                    }
                },
                "rating": 0.0,
                "icon": "https://lfcontentcenterdev.hwcloudtest.cn/pub_1/HuaweiMaps_camp_0_9/4/v3/7bwjt3bmRCaXa1R5icYriw/Petrol_Station.png",
                "internationalPhone": "",
                "poiTypes": [
                    "GAS_STATION"
                ],
                "phone": "",
                "websiteUrl": "www.ip.gruppoapi.com/",
                "childrenNodes": []
            },
            "name": "IP Station",
            "prediction": {
                "matchedKeywords": [
                    {
                        "offset": 3,
                        "value": "Station"
                    }
                ],
                "description": "IP Station Via del Boccella, Massarosa, Italy",
                "matchedWords": [
                    {
                        "offset": 0,
                        "value": "IP Station"
                    },
                    {
                        "offset": 11,
                        "value": "Via del Boccella"
                    },
                    {
                        "offset": 29,
                        "value": "Massarosa"
                    },
                    {
                        "offset": 40,
                        "value": "Italy"
                    }
                ]
            },
            "siteId": "853137832601337344",
            "location": {
                "lng": 10.265102,
                "lat": 43.895081
            }
        },
        {
            "formatAddress": "Via Dante Alighieri, Viareggio, Italy",
            "address": {
                "country": "Italy",
                "streetNumber": "2",
                "countryCode": "IT",
                "tertiaryAdminArea": "Viareggio",
                "postalCode": "55049",
                "locality": "Viareggio",
                "adminArea": "Tuscany",
                "subAdminArea": "Lucca",
                "thoroughfare": "Via Dante Alighieri"
            },
            "distance": 6056.436454634934,
            "poi": {
                "hwPoiTypes": [
                    "LOCAL_POST_OFFICE"
                ],
                "comments": {
                    "commentInfo": {},
                    "starInfo": {
                        "averageRating": "0.0"
                    }
                },
                "rating": 0.0,
                "icon": "https://lfcontentcenterdev.hwcloudtest.cn/pub_1/HuaweiMaps_camp_0_9/6/v3/nQcaLwJATMSdKH69UKrHzg/Post_Office.png",
                "internationalPhone": "+39 0584 353833",
                "poiTypes": [
                    "POST_OFFICE"
                ],
                "phone": "+39 0584 353833",
                "websiteUrl": "www.poste.it",
                "childrenNodes": []
            },
            "name": "station Torre del Lago Puccini",
            "prediction": {
                "matchedKeywords": [
                    {
                        "offset": 0,
                        "value": "station"
                    }
                ],
                "description": "station Torre del Lago Puccini Via Dante Alighieri, Viareggio, Italy",
                "matchedWords": [
                    {
                        "offset": 0,
                        "value": "station Torre del Lago Puccini"
                    },
                    {
                        "offset": 31,
                        "value": "Via Dante Alighieri"
                    },
                    {
                        "offset": 52,
                        "value": "Viareggio"
                    },
                    {
                        "offset": 63,
                        "value": "Italy"
                    }
                ]
            },
            "siteId": "653058557151948160",
            "location": {
                "lng": 10.2903156,
                "lat": 43.8268383
            }
        }
    ],
    "returnDesc": "OK"
}

Call Example

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

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

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

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

        try {
            location.put("lng", 2.4444);
            location.put("lat", 48.8815);

            json.put("query", "hotel");
            json.put("location", location);
        } 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("QuerySuggestion", e.toString());
            }

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