Overpass API Overpass Turbo – Get Center of Area Using Overpass Turbo

overpass-apioverpass-turbo

I have this query for overpass turbo ,

[out:json][timeout:25];
area["ISO3166-1:alpha2"="AM"][admin_level~"2"]->.search;
(way(area.search)[place~"town|city"];
 rel(area.search)[place~"town|city"];
)->.w;
.w map_to_area->.e;
.e out center tags;

This quer returns node like this:

{
  "type": "area",
  "id": 3610255555,
  "tags": {
    "admin_level": "6",
    "boundary": "administrative",
    "name": "Եղեգնաձոր",
    "name:de": "Jeghegnadsor",
    "name:en": "Yeghegnadzor",
    "name:hy": "Եղեգնաձոր",
    "name:it": "Jeghegnadzoras",
    "name:ja": "イェゲグナゾル",
    "name:pl": "Jeghegnadzor",
    "name:ru": "Ехегнадзор",
    "name:uk": "Єгеґнадзор",
    "place": "town",
    "population": "7944",
    "type": "boundary",
    "wikidata": "Q39538",
    "wikipedia": "hy:Եղեգնաձոր"
  }
},

How can I get lat and lng of this area or the center of area ?

Best Answer

"Areas" is an Overpass API internal artifact, which is not suitable to calculate a center point for. Instead you want to determine the center using out center; for both ways and relations:

[out:json][timeout:25];
area["ISO3166-1:alpha2"="AM"][admin_level~"2"]->.search;
wr(area.search)[place~"^(town|city)$"];
out center;