[Huawei Developers] berkberber:
If we briefly talk about what HMS Site Kit is, you can provide users to explore the world faster with Site Kit. You can search for locations by keywords, find places which are close to the specified coordinate point, get detailed information about a place and get suggestions for places by keyword.

With Place Search Suggestion which is another feature provided by the Site Kit, we can list the place suggestions of the values entered by user. If we given an example through a scenario, when user enters a value for search, we can show suggestions to user belong to places. For this case, we can use Place Search Suggestion feature provided by Site Kit.

Before I explain the use of Place Search Suggestion, I would like to share with you a function that we can use this feature.

fun placeSearchSuggestion(coordinate: Coordinate, keyword: String, radius: Int, locationTypes: List<LocationType>,
countryCode: String){
val searchService = SearchServiceFactory.create(context,
URLEncoder.encode(
"Your-API-KEY",
"utf-8"))

var request = QuerySuggestionRequest()
request.location = coordinate
request.query = keyword
request.radius = radius
request.poiTypes = locationTypes
request.countryCode = countryCode
request.language = Locale.getDefault().language // Getting system language

searchService.querySuggestion(request, object: SearchResultListener<QuerySuggestionResponse>{
override fun onSearchError(searchStatus: SearchStatus?) {
Log.e("SITE_KIT","${searchStatus?.errorCode} - ${searchStatus?.errorMessage}")
}

override fun onSearchResult(querySuggestionResponse: QuerySuggestionResponse?) {
var sites = querySuggestionResponse?.sites
sites?.let {
for(site in sites){
Log.i("SITE_KIT", "Name => ${site.name}," +
"Format address => ${site.formatAddress}, " +
"Coordinate => ${site.location.lat} - ${site.location.lng}, " +
"Phone => ${site.poi.phone}, " +
"Photo URLS => ${site.poi.photoUrls}, " +
"Rating => ${site.poi.rating}, " +
"Address Detail => ${site.address.thoroughfare}, ${site.address.subLocality}, " +
"${site.address.locality}, ${site.address.adminArea}, ${site.address.country}")
}
} ?: kotlin.run {
Log.e("SITE_KIT","No query suggestion found")
}
}

})
}

First, we need to create a SearchService object from the SearchServiceFactory class. For this, we can use the create() method of the SearchServiceFactory class. We need to declare two parameters in create() method.

The first of these parameters is context value. It is recommended that Context value should be in Activity type. Otherwise, when HMS Core(APK) needs to be updated, we can not receive any notification about it.

The second parameter is API Key value that we can access via AppGallery Connect. This value is generated automatically by AppGallery Connect when a new app is created. We need to encode API parameter as encodeURI.

After creating our SearchService object as I described above, we can create a QuerySuggestionRequest object. With this object, we will define the parameters that we have determined to get place suggestions.

To get place suggestions for the criteria which we have specified, we must first create a QuerySuggestionRequest object. The criteria we have determined allows place suggestions to change according to the needs of our application. Let us examine these parameters one by one if you want:

Location: We need to specify the coordinate points of region where we want to search. By creating a Coordinate object with latitude and longitude object, we can specify it in this parameter. Coordinate class is a class that Huawei provides to us. It holds latitude and longitude information.

Query: If we want to return places for specific keywords instead of searching for all places, we can use this parameter. It narrows and customizes search results according to the keywords we have specified.

Radius: It is used to make the search results within in a radius determined in meters. It can take values between 1 and 50000, and its default value is 50000.

PoiTypes: With PoiType, we can significantly change our search suggestions. PoiTypes takes values from LocationType class. For example, we can use LocationTypes.MUSEUM to search for museums and LocationTypes.RESTAURANT to search for restaurants. In the QuerySuggestionRequest object, poiTypes takes LocationType values in list type. In this way, we can expand results of our place suggestions by specifying more than one LocationType.

CountryCode: It is using to limit search results according to certain country borders.

Language: It is used to specify the language that search results have to be returned. If this parameter is not specified, language of the query field we have specified in the query field is accepted by default. In example code snippet in above, language of device has been added automatically in order to get a healthy result.

After determining the parameters belong to place suggestion process, we can perform the process of receiving place suggestions. We need to use querySuggestion() method of SearchService object to perform receiving the place suggestions belong to Place Search Suggestion feature. This method takes two parameters.

For the first parameter, we must specify the QuerySuggestionRequest object we have defined above.

For the second parameter, we have to implement SearchResultListener interface. Since this interface has a generic structure, we need to specify class belonging to the values to be returned. We can get the incoming values by specifying QuerySuggestionResponse object. Two methods must be override with this interface. onSearchError() method is executed if operation fails, and onSearchResult() method is executed if operation is successful. There is one value in QuerySuggestionResponse class. This value maintains a list of Site objects of places. We can access returned values with this Site object.