[Huawei Developers] Freemind R:
More articles like this, you can visit HUAWEI Developer Forum

​

Before starting this article follow previous article Site Kit (Keyword Search) for better understanding and project set up.

In this article find the following concepts.

· Nearby Place Search

· Place Details

· Place Search suggestion

Nearby Place Search: Huawei Site kit feature helps to get the nearby places using the current location of the user. For the nearby search we can set the POI (Point of Interest) where results can be filtered based on POI. User can search nearby Bakery, School, ATM etc.

Follow the steps.

Step 1: Create SearchService Object from the SearchServiceFactory

searchService = SearchServiceFactory.create(getActivity(), API_KEY);

Step 2: Create the NearBySearchRequest object which is used to request body for nearby search.

NearbySearchRequest request = new NearbySearchRequest();

Parameters of Nearby Place

Mandatory

· location: current location of a user.

Coordinate location = new Coordinate(12.9716, 77.5946);

Optional

· radius: search radius, in meters. The value ranges from 1 to 50000 meters. The default value is 1000mtr.

· query: search keyword.

· poiTypes: list of POI types.

· language: language in which search results are returned. For details about the value range, refer to language codes in Language Mapping. If this parameter is not passed, the language of the query field (preferred) or the local language is used.

· politicalView: Political view parameter. The value is a two-digit country code specified in the ISO 3166-1-alpha-2 standard.

· pageSize: number of records on each page. The value ranges from 1 to 20. The default value is 20.

· pageIndex: number of the current page. The value ranges from 1 to 60. The default value is 1.

Step 3: Create the SearchResultListener object to get the nearby place results.

Step 4: Use the SearchService Object (refer Step 1) to call the nearbySearch() and pass the nearby service request (refer Step 2) and also pass the SearchResultListener (refer Step 3).

Step 5: Get the nearby search response

private void findPlaceAroundMe() {
NearbySearchRequest request = new NearbySearchRequest();
Coordinate location = new Coordinate(12.9716, 77.5946);
request.setLocation(location);
request.setQuery("India");
request.setRadius(5000);
request.setPoiType(LocationType.ADDRESS);
request.setLanguage("In");
request.setPageIndex(1);
request.setPageSize(5);
// Create a search result listener.
SearchResultListener<NearbySearchResponse> resultListener = new SearchResultListener<NearbySearchResponse>() {
// Return search results upon a successful search.
@Override
public void onSearchResult(NearbySearchResponse results) {
AddressDetail addressDetail;
List<Site> sites = results.getSites();
if (results == null || results.getTotalCount() <= 0 || sites == null || sites.size() <= 0) {
return;
}
for (Site site : sites) {
Log.i("TAG", String.format("siteId: '%s', name: %s\r\n", site.getSiteId(), site.getName()));
}
if (results.getSites() != null && results.getSites().size() > 0) {
for (Site site : results.getSites()) {
searchModel = new SearchModel();
addressDetail = site.getAddress();
searchModel.setName(site.getName());
searchModel.setFormattedAddress(site.getFormatAddress());
searchModel.setCountry(addressDetail.getCountry());
searchModel.setCountryCode(addressDetail.getCountryCode());
searchModelList.add(searchModel);
}
SearchListAdapter searchListAdapter = new SearchListAdapter(searchModelList, getActivity());
searchResultList.setAdapter(searchListAdapter);
}
}

// Return the result code and description upon a search exception.
@Override
public void onSearchError(SearchStatus status) {
Log.i("TAG", "Error : " + status.getErrorCode() + " " + status.getErrorMessage());
}
};
// Call the nearby place search API.
searchService.nearbySearch(request, resultListener);
}

Place Details: Huawei Site kit feature helps to search for details about a place based on the unique ID (Site Id) of the place. SiteId can get from keyword or nearby or Place Suggestion search.

In Place details we can get the location name, formatted address, location website, location postal code, location phone numbers, and list of location images URL etc.

Follow the steps.

Step 1: Create SearchService Object from the SearchServiceFactory

searchService = SearchServiceFactory.create(getActivity(), API_KEY);

Step 2: Create the DetailSearchRequest object which is used to request body for place details search.

DetailSearchRequest request = new DetailSearchRequest();

Parameters of Place Details

Mandatory

· siteId: ID of a place.

Optional

language: language in which search results are returned. For details about the value range, refer to language codes in Language Mapping. If this parameter is not passed, the local language is used.

politicalView: Political view parameter. The value is a two-digit country code specified in the ISO 3166-1-alpha-2 standard.

Step 3: Create the SearchResultListener object to get the place detail results.

Step 4: Use the SearchService Object (refer Step 1) to call the detailSearch () and pass the detail search request (refer Step 2) and also pass the SearchResultListener (refer Step 3).

Step 5: Get the detail search response.

StringBuilder stringBuilder;
private void getDetailResultOfPlaceUsingSiteId(String siteId) {
DetailSearchRequest request = new DetailSearchRequest();
request.setSiteId(siteId);
request.setLanguage("En");
// Create a search result listener.
SearchResultListener<DetailSearchResponse> resultListener = new SearchResultListener<DetailSearchResponse>() {
// Return search results upon a successful search.
@Override
public void onSearchResult(DetailSearchResponse results) {
Site site = results.getSite();
if (results == null || site == null) {
return;
}
stringBuilder = new StringBuilder();
stringBuilder.append("Site Id: " + results.getSite().getSiteId() + "\n");
stringBuilder.append("Name: " + results.getSite().getName() + "\n");
stringBuilder.append("Formatted Address: " + results.getSite().getFormatAddress() + "\n");
stringBuilder.append("Distance: " + results.getSite().getDistance() + "\n");
stringBuilder.append("Country: " + results.getSite().getAddress().getCountry() + "\n");
stringBuilder.append("Country Code: " + results.getSite().getAddress().getCountryCode() + "\n");
stringBuilder.append("Locality: " + results.getSite().getAddress().getLocality() + "\n");
stringBuilder.append("Sub locality: " + results.getSite().getAddress().getSubLocality() + "\n");
/* stringBuilder.append("Postal Code: "+results.getSite().getAddress().getPostalCode()+"\n");
stringBuilder.append("Phone: "+results.getSite().getPoi().getPhone()+"\n");
stringBuilder.append("Website: "+results.getSite().getPoi().getWebsiteUrl()+"\n");
stringBuilder.append("Rating: "+results.getSite().getPoi().getRating()+"\n");*/

resultTv.setText(stringBuilder.toString());
Log.i("TAG", String.format("siteId: '%s', name: %s\r\n", site.getSiteId(), site.getName()));
}

// Return the result code and description upon a search exception.
@Override
public void onSearchError(SearchStatus status) {
Log.i("TAG", "Error : " + status.getErrorCode() + " " + status.getErrorMessage());
}
};
// Call the nearby place search API.
searchService.detailSearch(request, resultListener);
}

Place Search Suggestion: This Huawei Site kit feature helps us to return search suggestions during the user input.

Follow the steps.

Step 1: Create SearchService Object from the SearchServiceFactory

searchService = SearchServiceFactory.create(getActivity(), API_KEY);

Step 2: Create the QuerySuggestionRequest object which is used to request body for place details search.

QuerySuggestionRequest request = new QuerySuggestionRequest();

Parameters of Place Search Suggestion

Mandatory

· query: search keyword.

Optional

location: longitude and latitude to which search results need to be biased.

radius: search radius, in meters. The value ranges from 1 to 50000meters. The default value is 50000meters.

poiTypes: list of POI types. The options are as follows:

[IMG="https://miro.medium.com/max/599/1*7J8dLRoCoyAF1udtn7tjhQ.png"]https://miro.medium.com/max/599/1*7J8dLRoCoyAF1udtn7tjhQ.png[/IMG]

[IMG="https://miro.medium.com/max/593/1*oXSO_E4bTv-zASUcV-K5bg.png"]https://miro.medium.com/max/593/1*oXSO_E4bTv-zASUcV-K5bg.png[/IMG]​

countryCode: country code, which complies with the ISO 3166-1 alpha-2 standards. This parameter is used to restrict search results to the specified country.

language: language in which search results are returned. For details about the value range, refer to language codes in Language Mapping. If this parameter is not passed, the language of the query field (preferred) or the local language is used.

politicalView: Political view parameter. The value is a two-digit country code specified in the ISO 3166-1-alpha-2 standard.

Step 3: Create the SearchResultListener object to get the place search suggestion results.

Step 4: Use the SearchService Object (refer Step 1) to call the querySuggestion() and pass the query suggestion request (refer Step 2) and also pass the SearchResultListener (refer Step 3).

Step 5: Get the place suggestion search response

private void getQuerySuggestionResult(String query) {
QuerySuggestionRequest request = new QuerySuggestionRequest();
request.setQuery(query);
Coordinate location = new Coordinate(12.9716, 77.5946);
request.setLocation(location);
request.setRadius(1000);
request.setCountryCode("In");
request.setLanguage("In");
// Create a search result listener.
SearchResultListener<QuerySuggestionResponse> resultListener = new SearchResultListener<QuerySuggestionResponse>() {
// Return search results upon a successful search.
@Override
public void onSearchResult(QuerySuggestionResponse results) {
List<Site> sites = results.getSites();
if (results == null || sites == null || sites.size() <= 0) {
return;
}
AddressDetail addressDetail;
if (results.getSites() != null && results.getSites().size() > 0) {
for (Site site : results.getSites()) {
searchModel = new SearchModel();
addressDetail = site.getAddress();
searchModel.setName(site.getName());
searchModel.setFormattedAddress(site.getFormatAddress());
searchModel.setCountry(addressDetail.getCountry());
searchModel.setCountryCode(addressDetail.getCountryCode());
searchModelList.add(searchModel);
}
SearchListAdapter searchListAdapter = new SearchListAdapter(searchModelList, getActivity());
searchResultList.setAdapter(searchListAdapter);
}
}

// Return the result code and description upon a search exception.
@Override
public void onSearchError(SearchStatus status) {
Log.i("TAG", "Error : " + status.getErrorCode() + " " + status.getErrorMessage());
}
};
// Call the search suggestion API.
searchService.querySuggestion(request, resultListener);
}

Conclusion:

Huawei Site kit provides the following feature

· keyword search

· Nearby place search

· Place details

· Place suggestion search

From the above feature we can build application with location and place related application, we can also show all the place over Huawei map. Also search the place in the Huawei map using Site Kit.

Follow previous article Keyword Search

Result:

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090640.62049232136022676500404637139104:50510716030241:2800:4809EF7AD03534B6EE67E7550641436928DC023EB2A6D3DB776ED1301A94E559.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090640.62049232136022676500404637139104:50510716030241:2800:4809EF7AD03534B6EE67E7550641436928DC023EB2A6D3DB776ED1301A94E559.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090650.54722590168176183386816117762434:50510716030241:2800:4F86095CFED8C796A89CF2B5D2AA2775A85D4FAA8E05CF7909BFD754D7B628C7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090650.54722590168176183386816117762434:50510716030241:2800:4F86095CFED8C796A89CF2B5D2AA2775A85D4FAA8E05CF7909BFD754D7B628C7.png[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090658.77158467439580179959216057346443:50510716030241:2800:514683E1E62881D4F71FDB43332B6119E57ACF5EAE5F6CFFE5D8B6FE2C3DB89A.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/768/982/2640091000001768982.20200709090658.77158467439580179959216057346443:50510716030241:2800:514683E1E62881D4F71FDB43332B6119E57ACF5EAE5F6CFFE5D8B6FE2C3DB89A.png[/IMG]​