Document Maps JavaScript API Reference Manual Search PlaceSearch

PlaceSearch

AMap.PlaceSearch

Location search service plugin, providing location query services for a specific area. Construct a location search service plugin object

AMap.PlaceSearch(opts:PlaceSearchOptions)

Parameter

opts (PlaceSearchOptions)Location Search Parameters

Attribute

Type

Description

city

String

POI city, optional values: city name (Chinese or Chinese pinyin), citycode, adcode. City code table

citylimit

Boolean

Whether to force the search within the set city, default value: false true: force the search within the set city, false: do not force the search within the set city

children

Number

Whether to display sub-POI data hierarchically, default 0 children=1, display sub-node POI data, children=0, do not display sub-node data

type

String

POI categories, multiple categories separated by "|", such as "Restaurant|Hotel|Cinema". Default values: Food and Beverage Services, Business and Residential, Life Services. POI Classification Code

pageSize

Number

Number of results displayed per page, default value: 10, value range: 1-50, exceeding the value range will return the maximum value

pageIndex

Number

Page number (e.g., if pageIndex is 2 and pageSize is 10, then the displayed results should be the 11th to 20th returned results), default value: 1, value range: 1-100, exceeding the actual number of pages will not return poi

extensions

String

Default value for this item: base, returns basic address information. Value: all, returns basic + detailed information

map

Map

AMap.Map object, the map instance that displays the results. When this parameter is specified, the labels and routes of the search results will be automatically added to this map. Optional value

panel

String|HTMLElement

The HTML container ID or container element for the result list. After providing this parameter, the result list will be displayed in this container. Optional value

showCover

Boolean

When using the map property, whether to display the circle for nearby search or the polygon for range search on the map, default is true

autoFitView

Boolean

Used to control whether to automatically adjust the map view after the search is completed so that the drawn Marker points are within the visible range of the viewport

Demo

AMap.plugin(["AMap.PlaceSearch"], function () {
            var PlaceSearchOptions = {
              city: "840380000",
              type: "博物馆",
              pageSize: 10, 
              pageIndex: 1, 
              extensions: "base",
            };
            var placeSearch = new AMap.PlaceSearch(PlaceSearchOptions);
            placeSearch.search("food", function (status, result) {
              console.log(result);
            }); 
          });

Method

search(keyword, callback)

Match information based on input keyword prompts

Parameter:

keyword (stringKeyword

callback (searchCallbackSearch results callback

Demo:

placeSearch.search("food", function (status, result) {
  console.log(result);
}); 

searchInBounds(keyword, bounds, callback)

Perform a range search based on the scope and keyword

Parameter:

keyword (stringKeyword

bounds (BoundsRange

callback (searchCallbackSearch results callback

Demo:

var polygonArr = [
  [-73.509092,40.793609],
  [-73.487738,40.769018],
  [-73.446643,40.768289],
  [-73.424987,40.793844],
];
placeSearch.searchInBounds("food", polygonArr, function (status, result) {
  console.log(result);
});

searchNearBy(keyword, center, radius)

Perform a nearby search based on the center point latitude and longitude, radius, and keyword. The radius range is 0-50000

Parameter:

keyword (stringKeyword

center (LngLatCenter Point Latitude and Longitude

radius (numberRadius

Demo:

var cpoint = [103.861974,1.304754]; 
MSearch.searchNearBy("food", cpoint, 2000, function (status, result) {
  console.log(result);
});

getDetails(PGUID)

Query POI Details Based on PGUID

Parameter:

PGUID (string) PGUID

Demo:

placeSearch.getDetails("P0JAK55X50", function (status, result) {
  console.log(result);
});

setType(type)

Set Query Categories, Multiple Categories Separated by "|"

Parametertype (stringCategory

Demo:

placeSearch.setType('餐饮服务');

setPageIndex(pageIndex)

Set Display Result Page Number

ParameterpageIndex (numberResult Page Number

Demo:

placeSearch.setPageIndex(1);

setPageSize(pageSize)

Set the number of query results displayed per page

ParameterpageSize (numberNumber of query results displayed per page

Demo:

placeSearch.setPageSize(10);

setCity(city)

Set the query city, supports cityname (Chinese or full Pinyin), citycode, adcode

Parametercity (stringCity identifier

Demo:

placeSearch.setCity('beijing');

setCityLimit(citylimit)

Set whether to enforce city restrictions

Parametercitylimit (booleanWhether to enable

Demo:

placeSearch.setCityLimit(true);

Event

selectChanged

Triggered when the selected POI changes after using map and panel properties

Parameterevent (objectReturn parameters

Attribute

Type

Description

type

string

Event category

id

string

ID of the currently selected POI

marker

Marker

The Marker object corresponding to the currently selected POI on the map

listElement

HTMLElement

The list item corresponding to the currently selected POI in the result panel

data

POI

Information of the currently selected POI

markerClick

Triggered when the Marker corresponding to the POI on the map is clicked after using the map and panel properties

Parameterevent (objectReturn Parameters

Attribute

Type

Description

type

string

Event category

id

string

ID of the currently selected POI

marker

Marker

Marker object corresponding to the currently selected POI on the map

listElement

HTMLElement

List item corresponding to the currently selected POI in the results panel

data

POI

Information of the currently selected POI

listElementClick

When the list item corresponding to the POI in the result panel is clicked after using the map and panel attributes

Parameterevent (objectReturn Parameters

Attribute

Type

Description

type

string

Event category

id

string

ID of the currently selected POI

marker

Marker

Marker object corresponding to the currently selected POI on the map

listElement

HTMLElement

List item corresponding to the currently selected POI in the results panel

data

POI

Information of the currently selected POI