ym.modules.AutoComplete

There is a new version of the autocomplete available. Please use version 5 of the autocomplete for your future projects.

Initialization

To initialize the Autocomplete component

Code example: Initialization Auto-Complete

// Create the class directly.
var autocomplete1 = new ym.modules.AutoComplete('#autocomplete1',
{
	dataType: "jsonp",
	onSelected: function(geoJson){
		geocoder.geocode(geoJson.properties.location);
	}
});

// Use the Factory to create the instance.
var autocomplete2 = ym.modules.autoComplete('#autocomplete2',
{
	dataType: "jsonp",
	onSelected: function(geoJson){
		geocoder.geocode(geoJson.properties.location);
	}
});

Constructor(selector, settings)

Parameter: selector

In the selector field, a jQuery object or a CSS3 selector can be passed that points to the input field for the autocomplete.

Parameter: settings

Name Description Data type Default value
limit Maximum number of hits to be displayed in Autocomplete. string 8
url The URL to the Autocomplete WebService. string https://autocomplete.yellowmap.de/
Autocomplete/Search
dataType There are 3 data types: "json""jsonp" and "protobuf". string "json"
locales

The countries to search in: You can pass a string with a country code or an array with any number of country codes. If locales is left completely empty, all countries are searched.

Google Maps
If you use SmartMaps together with Google Maps only 5 country codes can be transferred at the moment.

  string
onInit(address, query) The event onInit is called when an Autocomplete call is started. event  
onSuggestion(geoJson, query) As soon as a list of hits is received, onSuggestion is called. It receives a GeoJson and the search query. event  
onEmpty(query) If no hits at all could be determined by the autocomplete, onEmpty is called. Here only the search query is returned. event  
onSelected(geoJson, query) The selection of a hit in the Autocomplete suggestion list triggers onSelected. This event returns a GeoJson and the search query. event  
onError(error) If there is a server-side problem or a problem with the data connection, this event is triggered. event  

Methods

setMap(map) from v3

Registers a map for the Autocomplete search. If the map is registered in Autocomplete, the rectangle of the map section is automatically used as search area for localization.

Codebeispiel: setMap(map)

autocomplete.setLatLng(ym.latLng(49, 10));

removeMap() from v3

Removes the registered card from the Autocomplete search. By removing the map there is no more localization.

setLatLng(latLng) from v3

Defines a search area using the radius set in the options, in which the search query should be executed.

Codebeispiel: setLatLang(latLng)

var autocomplete = ym.modules.autoComplete(element, settings);
autocomplete.setMap(map); 

setBounds(latLngBounds) from v3

Defines a search area using a search rectangle.

Codebeispiel: setBounds(latLngBounds)

autocomplete.setBounds(ym.latLngBounds(ym.latLng(49, 10), ym.latLng(50, 11));

getLatLng() from v3

If available, a LatLng-object is returned which defines the center of the search rectangle. If no search rectangle is defined, undefined is returned.

getBounds() from v3

If available, a LatLngBounds-object is returned that defines the search rectangle. If no search rectangle is defined, undefined is returned.