目录

POI Search

Use Cases

The following POI information search capabilities are provided:

API Description

The following table describes APIs for POI search, which are mainly provided by methods in the site namespace. For more information about the APIs, please refer to API Reference.

API Description
searchByText(searchByTextParams: SearchByTextParams): Promise<SearchByTextResult> Performs keyword search.
searchByText(context: common.Context, searchByTextParams: SearchByTextParams): Promise<SearchByTextResult> Performs keyword search. The context can be passed.
nearbySearch(nearbySearchParams: NearbySearchParams): Promise<NearbySearchResult> Performs nearby place search.
nearbySearch(context: common.Context, nearbySearchParams: NearbySearchParams): Promise<NearbySearchResult> Performs nearby place search. The context can be passed.
queryAutoComplete(queryAutoCompleteParams: QueryAutoCompleteParams): Promise<QueryAutoCompleteResult> Performs autocomplete.
queryAutoComplete(context: common.Context, queryAutoCompleteParams: QueryAutoCompleteParams): Promise<QueryAutoCompleteResult> Performs autocomplete. The context can be passed.
searchById(searchByIdParams: SearchByIdParams): Promise<SearchByIdResult> Searches for place details.
searchById(context: common.Context, searchByIdParams: SearchByIdParams): Promise<SearchByIdResult> Searches for place details. The context can be passed.

Development Procedure

Import required modules.

import { site } from '@kit.MapKit';
import { BusinessError } from '@kit.BasicServicesKit';

[h2]Autocomplete

This capability presents the most possible search terms to users based on their input keywords to reduce the amount of information they need to enter and improve their experience. For example, if a user enters Beijing, this capability suggests Beijing, Beijing Railway Station, and Beijing West Railway Station.

let params: site.QueryAutoCompleteParams = {
  // Custom keyword.
  query: 'hotel',
  // Longitude-latitude coordinates.
  location: {
    latitude: 31.984410259206815,
    longitude: 118.76625379397866
  },
  language: 'en',
  // Return child nodes.
  isChildren: true
};
// Return the autocomplete result.
try {
  const result = await site.queryAutoComplete(params);
  console.info(`Succeeded in querying. result is ${JSON.stringify(result)}`);
} catch (error) {
  const err: BusinessError = error as BusinessError;
  console.error(`Failed in querying. Code is ${err.code}, message is ${err.message}`);
}