目录

Keyword Search

With this function, users can specify keywords, coordinate bounds, and other information to search for places such as tourist attractions, enterprises, and schools.

Procedure

  1. Initialize the HWSiteService object through HWMapJsSDK.
  2. Construct a keyword search request. In the request, the query parameter is mandatory and other parameters are optional. The politicalView parameter has been deprecated.

    • query: search keyword.
    • location: longitude and latitude to which search results need to be biased.
    • radius: search radius, in meters. The value ranges from 1 to 50,000. The default value is 50000.
    • poiType: type of the POI to be returned.
    • countryCode: code of the country where places are searched. The country code must comply with the ISO 3166-1 alpha-2 standard.
    • language: language in which the search results are displayed. If no language is specified, the local language will be used.
    • pageSize: number of records on each page. The value ranges from 1 to 20. The default value is 20.
    • pageIndex: current page number. The value ranges from 1 to 60. The default value is 1.
    • countries: codes of multiple countries or regions. The value is multiple two-letter country or region codes complying with ISO 3166-1 alpha-2.
    • politicalView: political view. The value is a two-letter country or region code complying with the ISO 3166-1 alpha-2 standard. This parameter has been deprecated.

  3. Call the searchByText API through the initialized HWSiteService object, and pass the created request.
  4. Obtain the search result. You can obtain the search result (result) and search status (status) through the callback functions of the searchByText API. For details about status, please refer to Result Codes. The result contains the following fields:

    • sites: search result, which is a Site[] array. For details about the array, please refer to Parameters.
    • totalCount: total number of search result records.

Sample Code

function initMap(){
    var map;
    var mapOptions = {};
    mapOptions.center = {lat: 48.856613, lng: 2.352222};
    mapOptions.zoom = 15;
    map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
    var siteService
    // Initialize the HWSiteService object.
    siteService = new HWMapJsSDK.HWSiteService();
    // Construct a request.
    var request = {
	    query: "Paris"
    };
    // Call the search API. In the API, result indicates the search result and status indicates the search status. 
    siteService.searchByText(request, function (result, status) {
	if (status == '0') {
		for (var i = 0; i < result.sites.length; i++) {
			// Add a marker on the map.
			var marker = new HWMapJsSDK.HWMarker({
				map: map,
				position: {lat: result.sites[i].location.lat, lng: result.sites[i].location.lng},
				label: result.sites[i].name
			});
		}
		// Set the map center.
		map.setCenter({lat: result.sites[0].location.lat, lng: result.sites[0].location.lng})
	}
    });
}