Searching an address |
search function
Searches for address points in according to the specified address. Data transmitted to the substitution in the second parameter containing a list of matching feature address's points (geocodeInfoArray) included:
Geographic coordinates are returned only for the first item from the list of results. If any of the components present in the output section address, that means it has been rejected during the search.
Available parameters:
address | {String} Address to search for in the format "(city|code)[,street [number]][;code|adm1[,adm2[,adm3]])]", which means that at the beginning there is a city or a zip code, then optionally after decimal a street with possible number and then optional after the semicolon postal code or list of three administrative areas (from the highest to the lowest level) separated by commas. The letters's size doesn't matter. |
callback | {Function} The service function of searching results. |
var map = new EMAPI.Map('mapa1','userId'); var finder = new EMAPI.Finder(map); // creating a new instance of EMAPI.Finder dla mapy 'map' finder.search("kowiesy", onfind); //searching the city Kowiesy and inductione //the onfind function to support results onfind= function(res) { alert(res.geocodeInfoArray[0].areaName0); //induction a window with information including the name } // voivodeship searching cities
The results of the search function are provided in the matrix form.
Example:
{ "result":0, "geocodeInfoArray": [ { "city":"Kowiesy", "zip":"96-320", "street":"", "streetNumber":"", "areaName0":"Mazowieckie", "areaName1":"żyrardowski", "areaName2":"Mszczonów", "middlePoint":{"Longitude":20.5306243896484,"Latitude":51.8994674682617}, "boundingRect": { "TopLeft":{"Longitude":20.527961730957,"Latitude":51.8912010192871}, "BottomRight":{"Longitude":20.5423965454102,"Latitude":51.9019966125488} }, "geocodeType":0}, { "city":"Kowiesy", "zip":"08-311", "street":"", "streetNumber":"", "areaName0":"Mazowieckie", "areaName1":"sokołowski", "areaName2":"Bielany", "middlePoint":null, "boundingRect":null, "geocodeType":3 }, { "city":"Kowiesy", "zip":"96-111", "street":"", "streetNumber":"", "areaName0":"Łódzkie", "areaName1":"skierniewicki", "areaName2":"Kowiesy", "middlePoint":null, "boundingRect":null, "geocodeType":3 } ] };
getCoordinates function
Gets the location one of the address points from the map searched using the search function Data transmitted to the substitution in the second parameter function contains an element of the structure passed according to the search function, returns the suitable error code (result: 0 = ok, 1 = invalid index position on the list of results).
Available parameters:
index | {Integer} The position of the desired item from the list of searching results (a value from the range 0-[ number of results reduced by 1]). |
callback | {Function} The service function of searching results. |
Example of setting the map view for a sophisticated city:
finder.getCoordinates(0, responseCoordinate); //download location of the first sophisticated point //and orward it to the responseCoordinate function responseCoordinate = function(response) { if (response.result == 0) { var bounds = new EMAPI.Bounds( response.boundingRect.TopLeft.Longitude, // response.boundingRect.BottomRight.Latitude, //coordinates of the rectangle's vertices response.boundingRect.BottomRight.Longitude, //presenting the map response.boundingRect.TopLeft.Latitude); // map.setBounds(bounds); //sets the map view to a sophisticated city } }
The list of search results function and map presents the first sophisticated town.