Meklēšanas serviss
Autocomplete meklētājs. Var tikt izmantots arī kā mazāk strikts ģeokodētājs.
Servisa URL
Servisa saitei jāatbilst šādai formai:
https://api.kartes.lv/v3//search?
Noklusētais atgriezto datu formāts ir JSON (pieejami arī JSONP un XML).
HTTP metode ir GET.
Pieprasījuma parametri
Iespējams padot šādus GET parametrus:
| Parametrs | Skaidrojums | Pieejamās vērtības |
|---|---|---|
| q | Vaicājums. Vaicājumus var veikt, izmantojot objekta saīsināto vai pilno nosaukumu, pilnu vai daļēju adresi, kadastra apzīmējumu (kadastra vienībām un ēkām) vai uzņēmuma reģistrācijas numuru. POI objektiem nosaukuma vai adreses vaicājumu var apvienot ar apakškategorijas atslēgvārdu latviešu valodā (piemēram, veikals – veikalam, viesnīca – viesnīcai) | Parametrs obligāts |
| mode |
|
|
| layers | Datu slāņi, kuros meklēt (sk. zemāk) | |
| iso_code | Valsts ISO kods (LVA — Latvija, EST — Igaunija, LVA — Lietuva). Drīkst kombinēt, atdalot ar komatu. |
|
| format | JSON vai GeoJSON |
|
| geometry | Objekta pilnā ģeometrija | Bez parametra |
| fields | Satur atgriežamo lauku nosaukumus, jāatdala ar komatu. | Parametrs obligāts
|
| cs | Iespēja norādīt koordinātu sistēmu, kurā tiek atgriezti dati. |
|
| limit | Katrā slānī maksimāli atgriežamo objektu skaits. | Skaitlis no 1 līdz 50 (noklusējuma vērtība) |
| pop_place_level | Norāda, ka meklē tikai pilsētās (tikai adresēm). |
|
| address_code | Adreses kods (tikai adresēm). Ļauj atrast adreses pēc koda. | Piemērs: 105747812 |
| magicKey | Ja ir padots, tad meklēšanā tiek izmantots tikai šis norādītais hešs (tikai adresēm). | |
| region | Ja ir padots, tad meklēšana notiek tikai norādītajā apgabalā (pagastā, novadā, rajonā), var padot vairākas vērtības, atdalot ar komatu. Iespējams padot WKT laukumu ģeometrijas (POLYGON). Aktuāls tikai adresēm. | Piemēri: Cēsu novadsLatgales priekšpilsētaCēsu novads, Valmieras novads'POLYGON ((24.25309903890031 57.01492713579236, 24.261838178785016 56.841545957617114, 23.963459524961085 56.83369239854119, 23.934745262080735 57.008809515780456, 24.25309903890031 57.01492713579236))' |
| post | Ja ir padots, tad meklēšana notiek tikai norādītajos pasta indeksos (tikai adresēm) | Formāts: LV-1021,LV-1050 |
| postGroups | Ja ir padots, tad meklēšana notiek tikai norādītajās pasta indeksu "grupās" (tikai adresēm) | Formāts: LV-10,LV-54 |
Pieejamie datu slāņi
- apdz_vieta - apdzīvotās vietas,
- adrese - adreses,
- admin_vien - administratīvās vienības,
- terit_vien - teritoriālās vienības,
- iela - ielas, autoceļi (var meklēt arī pēc valsts autoceļa numura vai LVM ceļa nosaukuma),
- river - upes,
- lake - ezeri,
- mountain - kalni,
- cadastral - kadastra zemes vienība,
- cadastral_building - kadastra būve,
- hotels - viesnīcas,
- fuel - degvielas vai gāzes uzpildes stacijas, uzlādes stacijas,
- education - izglītības iestādes,
- religion - reliģiskās celtnes, dievnami,
- culture - kultūras objekti,
- shopping - tirdzniecības centri,
- nature - dabas objekti,
- catering - ēdināšanas uzņēmumi,
- finance - finanšu iestādes,
- health_care - medicīnas iestādes,
- public_institution - sabiedriskās institūcijas, uzņēmumi,
- sport_recreation -sporta objekti,
- tourism - tūrisma objekti,
- transport - sabiedriskā transporta objekti,
- swamp - purvi,
- island - salas,
- park_forest - parki, meži,
- protected_area - aizsargājamās dabas teritorijas,
- historical_address - vēsturiskās adreses,
- organization - organizācijas vai uzņēmumi (Uzņēmuma reģistra atvērtie dati)
Atbildes parametri
Atbildē tiek atgriezti pieprasītie datu slāņi, katrā slānī ir masīvs ar objektiem, kas satur ievadlaukā fields definētos parametrus.
Kļūdu kodi
| Kods | Skaidrojums |
|---|---|
| 400 | Wrong input data. Tiek atgriezts, ja vaicājumā nav ievadīti vai nav korekti ievadīti pieprasījuma parametri. |
| 404 | No location found. Tiek atgriezts, ja nekas nav ticis atrasts. |
| 5xx | Servera kļūda. |
Paraugi
Adrešu meklēšana
Pieprasījums:
https://api.kartes.lv/v3//search?q=krasta%20105%20riga&layers=adrese&cs=wgs84&fields=name,maja,iela,pop_place,terit_vien,admin_vien,iso_code,index,x,y
Atbilde:
{
"adrese": [
{
"name": "Krasta iela 105, Rīga, Latgales pr-pilsēta, Latvija",
"maja": "105",
"iela": "Krasta iela",
"pop_place": "Rīga",
"terit_vien": "Latgales priekšpilsēta",
"admin_vien": "Rīga",
"iso_code": "LVA",
"index": "LV-1019",
"x": 24.16781,
"y": 56.921167
},
{
"name": "Krasta iela 105A, Rīga, Latgales pr-pilsēta, Latvija",
"maja": "105A",
"iela": "Krasta iela",
"pop_place": "Rīga",
"terit_vien": "Latgales priekšpilsēta",
"admin_vien": "Rīga",
"iso_code": "LVA",
"index": "LV-1019",
"x": 24.168581,
"y": 56.921337
}
]
}
Citi
Pieprasījums:
https://api.kartes.lv/v3//search?q=rododendru%20iela%20rīga&layers=iela&cs=wgs84&fields=name,pop_place,iso_code,x_min,y_min,x_max,y_max,x_first,y_first,the_geom
Atbilde:
{
"iela": [
{
"name": "Rododendru iela",
"pop_place": "Rīga",
"iso_code": "LVA",
"x_min": "24.047660",
"y_min": "56.947559",
"x_max": "24.054698",
"y_max": "56.949043",
"x_first": "24.054698",
"y_first": "56.949043",
"the_geom": "{\"type\":\"LineString\",\"coordinates\":[[24.054698,56.949043],[24.054496,56.949013],[24.054241,56.948963],[24.054123,56.948921],[24.053951,56.94885],...}"
}
]
}
Pieprasījums:
https://api.kartes.lv/v3//search?q=berlīne&cs=wgs84&format=geojson&fields=name,pop_place,iso_code,x_min,y_min,x_max,y_max,x_first,y_first,the_geom
Atbilde:
{
"apdz_vieta": {
"type": "FeatureCollection",
"name": "apdz_vieta",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"adrese": {
"type": "FeatureCollection",
"name": "adrese",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
26.328814,
56.977481
]
},
"properties": {
"name": "Berlīne, Cesvaines pag., Madonas nov., Latvija",
"iso_code": "LVA"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
25.668572,
57.19281
]
},
"properties": {
"name": "Berlīne, Dzērbene, Dzērbenes pag., Cēsu nov., Latvija",
"pop_place": "Dzērbene",
"iso_code": "LVA"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
26.606173,
56.826337
]
},
"properties": {
"name": "Berlīne, Meirāni, Indrānu pag., Madonas nov., Latvija",
"pop_place": "Meirāni",
"iso_code": "LVA"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
24.946032,
57.347814
]
},
"properties": {
"name": "Berlīne, Straupe, Straupes pag., Cēsu nov., Latvija",
"pop_place": "Straupe",
"iso_code": "LVA"
}
}
]
},
"admin_vien": {
"type": "FeatureCollection",
"name": "admin_vien",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"terit_vien": {
"type": "FeatureCollection",
"name": "terit_vien",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"iela": {
"type": "FeatureCollection",
"name": "iela",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": [
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[
24.820069,
56.534862
],...
],...
]
},
"properties": {
"name": "Berlīnes ceļš",
"iso_code": "LVA",
"x_min": "24.820069",
"y_min": "56.523434",
"x_max": "24.826498",
"y_max": "56.534862",
"x_first": "24.820069",
"y_first": "56.534862"
}
},
{
"type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [
[
[
24.616246,
56.894385
],...
],...
},
"properties": {
"name": "Berlīnes līnija",
"iso_code": "LVA",
"x_min": "24.616246",
"y_min": "56.893761",
"x_max": "24.687871",
"y_max": "56.908783",
"x_first": "24.616246",
"y_first": "56.894385"
}
}
]
},
"river": {
"type": "FeatureCollection",
"name": "river",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"lake": {
"type": "FeatureCollection",
"name": "lake",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"mountain": {
"type": "FeatureCollection",
"name": "mountain",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"cadastral": {
"type": "FeatureCollection",
"name": "cadastral",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"cadastral_building": {
"type": "FeatureCollection",
"name": "cadastral_building",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"hotels": {
"type": "FeatureCollection",
"name": "hotels",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"fuel": {
"type": "FeatureCollection",
"name": "fuel",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"education": {
"type": "FeatureCollection",
"name": "education",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"religion": {
"type": "FeatureCollection",
"name": "religion",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"culture": {
"type": "FeatureCollection",
"name": "culture",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"shopping": {
"type": "FeatureCollection",
"name": "shopping",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"nature": {
"type": "FeatureCollection",
"name": "nature",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
25.3277100919886,
57.3563960998154
]
},
"properties": {
"name": "Berlīne",
"iso_code": "LVA"
}
}
]
},
"catering": {
"type": "FeatureCollection",
"name": "catering",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"finance": {
"type": "FeatureCollection",
"name": "finance",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"health_care": {
"type": "FeatureCollection",
"name": "health_care",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"public_institution": {
"type": "FeatureCollection",
"name": "public_institution",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"sport_recreation": {
"type": "FeatureCollection",
"name": "sport_recreation",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"tourism": {
"type": "FeatureCollection",
"name": "tourism",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
24.1041293486792,
56.9585196144391
]
},
"properties": {
"name": "Berlīnes mūra fragments",
"pop_place": "Rīga",
"iso_code": "LVA"
}
}
]
},
"transport": {
"type": "FeatureCollection",
"name": "transport",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"swamp": {
"type": "FeatureCollection",
"name": "swamp",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"island": {
"type": "FeatureCollection",
"name": "island",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"park_forest": {
"type": "FeatureCollection",
"name": "park_forest",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"protected_area": {
"type": "FeatureCollection",
"name": "protected_area",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": []
},
"historical_address": {
"type": "FeatureCollection",
"name": "historical_address",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::4326"
}
},
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
25.668572,
57.19281
]
},
"properties": {
"name": "Berlīne, Dzērbenes pag., Cēsu raj., Latvija",
"iso_code": "LVA"
}
}
]
}
}
Pielietošanas piemēri
Meklēšanas klases definēšana JavaScript kodā:
class SearchApi {
constructor() {
this.apiKey = 'your_api_key_here'; // Replace with your actual API key
this.baseUrl = 'https://api.kartes.lv/v3';
}
// Method to perform the search
async search(query) {
const params = new URLSearchParams({
q: query,
layers: 'adrese',
cs: 'wgs84',
fields: 'name,maja,iela,pop_place,terit_vien,admin_vien,iso_code,index,x,y'
});
const url = `${this.baseUrl}/${this.apiKey}/search?${params.toString()}`;
try {
const response = await fetch(url);
// Check if the response is ok (status code 200-299)
if (!response.ok) {
throw new Error(`Error fetching data: ${response.statusText}`);
}
const data = await response.json();
return { success: true, data };
} catch (error) {
console.error('Fetch error:', error);
return { success: false, error: error.message };
}
}
}
Meklēšanas klases pielietošana:
const api = new SearchAPI('your_api_key'); // Replace with your actual API key
const query = 'krasta 105a riga';
api.search(query)
.then(result => {
if (!result.success) {
console.error('Error:', result.error); // Handle the error
return;
}
console.log(result.data);
// Use the data
});