ym.services.GeoCoder

Initialization

GeoCoder is initialized as follows:

var geocoder = new ym.services.GeoCoder();  

Constructor(options)

The options parameter is not required.

The constructor uses the standard definition from ym.provider.GeoJSON and extends it with some properties:

Name Description Data type Default value
channel Eine Zeichenfolge, die protokolliert wird; sie kann vom Benutzer frei gewählt werden. string  

Methods

GeoCoder.geocode(location, options) from v3

You can use this method to geocode an address as a location object. The following components of a postal address can be passed:

Parameter: location

Name Description Data type Default value
country Land string  
district Bundesland oder Bundesstaat string  
zip Postleitzahl string  
city Ort string  
cityPart Teilort string  
cityAddon Zusätzliche Information zur Stadt oder zum Ort string  
street Straßenname string  
houseNo Hausnummer string  

Parameter: option

The options correspond to those of the constructor. By default, the options from the constructor and the parent class are used. If the options are set here, they overwrite the previously set options for this call.

Call

Codebeispiel: GeoCoder.geocode(location, options) Call Example

geocoder.geocode({
zip: "76131",
city: "ka"
},
{
coordFormat: "GEODECIMAL_POINT",
locale: "de-DE",
channel: "mobile device"
});

GeoCoder.geocodeString(singleSlot, options) from v3

This method is similar to the geocode()-method. The difference is that a free text can be passed.

Parameter: singleSlot

All address information is passed as single-line information, for example "CAS-Weg 4, 76131 Karlruhe" (comma optional). The method geocodeString() is especially useful, if there is a single text input field on the page, where an address is to be entered.

Parameter: option

The options correspond to those of the constructor. By default, the options from the constructor and the parent class are used. If the options are set here, they overwrite the previously set options for this call.

Call

Code example: GeoCoder.geocodeString(singleSlot, options) Example call

geocoder.geocodeString("Marktplatz, Karlsruhe");

GeoCoder.reverseGeocode(latLng, options) from v3

Parameter: latLng

Allowed data types are: ym.modules.provider.LatLng{lat:Number, lng:Number} or an array in format [latitude, longitude]

Parameter: options

The options correspond to those of the constructor. By default, the options from the constructor and the parent class are used. If the options are set here, they overwrite the previously set options for this call.

Call

Code example: GeoCoder.reverseGeocode(latLng, options) Example call

geocoder.reverseGeocode({lat: 48.9941241, lng: 8.3510868});
geocoder.reverseGeocode([48.9941241, 8.3510868]);
geocoder.reverseGeocode(ym.latLng(48.9941241, 8.3510868));
geocoder.reverseGeocode(new ym.modules.provider.LatLng(48.9941241, 8.3510868));

Events

To track a geocoding, the Geocoder is equipped with an event emitter that supports two events:

Code example: Events

geocoder.on('success', function (request, response) {
	if (response.body) {
		var geoJson = ym.geoJson(response.body);
		geoJson.addTo(map);
	}
});
 
geocoder.on('error', function (request, response) {
	console.log(response.xhr);
	console.log(response.event);
});