Document Maps JavaScript API Reference Manual Search AutoComplete

AutoComplete

AMap.AutoComplete

Match information based on input keyword prompts, and use POI type and city as input prompt restrictions. Users can retrieve and display through a custom callback function. Construct an input prompt plugin object

new AMap.AutoComplete(opts: object)

Parameter

opts (object) Input prompt parameters

Attribute

Type

Description

type

string

Limit the POI type when inputting prompts. Multiple types are separated by "|". Currently, only POI type codes such as "050000" are supported. Default value: all categories. POI classification code

city

string

Limit the city when inputting prompts. Optional values: city name (Chinese or Chinese pinyin), citycode, adcode; city code table"

datatype

string

The type of data returned. Optional values: all-return all data types, poi-return POI data type, bus-return bus stop data type, busline-return bus line data type. Currently, multiple types are not supported

citylimit

boolean

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

input

string | HTMLDivElement

Optional parameter, used to specify an input box, after setting, a dropdown selection list will be automatically generated when text is entered in the input. Supports passing the id value of the input box DOM object or directly passing the input box DOM object

output

string | HTMLDivElement

Optional parameter, specifying an existing div's id or element as the container for displaying prompt results, effective when an input is specified, and a result display panel will be automatically created by default

outPutDirAuto

boolean

Default is true, indicating whether to automatically display the input panel above the input when the input is located lower on the page to avoid being obscured

closeResultOnScroll

boolean

Close the search results list when the page scrolls, default true

Demo

AMap.plugin("AMap.AutoComplete", function () {
  var autoOptions = {
    city: "724010000", 
  };
  var autoComplete = new AMap.AutoComplete(autoOptions);
});

Method

setType(type)

Set prompt Poi types, multiple types are separated by '|'. For related Poi types, please download from the 'Related Downloads' section on the website. Currently, only Poi type codes such as '050000' are supported. Default value: all categories

Parametertype (StringPrompt Poi type

Demo:

autoComplete.setType(“050000”);

setCity(city)

Set city

Parametercity (StringCity

Demo:

autoComplete.setCity('724010000');

setCityLimit(citylimit)

Set whether to enforce city restrictions

Parametercitylimit (booleanWhether to enforce city restrictions

Demo:

autoComplete.setCityLimit(true);

search(keyword, callback)

Provide matching information based on input keywords

Parameter:

keyword (StringKeyword

callback (AutoCompleteSearchCallbackSearch result callback

Demo:

//Search based on keywords, where 'keyword' is the search term
autoComplete.search(keyword, function (status, result) {
  //When the search is successful, the result is the corresponding matching data
  console.log(result);
});

Event

select

This event is triggered when a POI information is selected by mouse click or pressing enter

Parameterevent (objectReturn Parameters

Attribute

Type

Description

id

string

POI Unique Identifier

name

string

Name

adcode

string

Area Code

district

string

Belonging Area

location

LngLat

Location

type

string

Type

choose

This event is triggered when selecting POI information with the mouse or the up and down keys on the keyboard

Parameterevent (objectReturn Parameters

Attribute

Type

Description

id

string

POI Unique Identifier

name

string

Name

adcode

string

Area Code

district

string

Belonging Area

location

LngLat

Location

type

string

Type