Reverse geolocation with OpenStreet Maps reverse geocoder. Pros and cons
Reverse geolocation is a process of obtaining certain geographical information (like street name, city, country etc.) based on geographical coordinates only.
OpenStreet Maps offers a cool looking (at least at first sight) reverse geocoder that can feed your application or website with a valuable geolocation data. However, as you go deeper in to the details, more cons over pros can appear.
Here is an example query to
And here is an example result:
<reversegeocode timestamp="Thu, 08 Dec 16 16:19:58 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="lat=50.250000&lon=19.000000&zoom=15"> <result place_id="40761272" osm_type="node" osm_id="3009713252" ref="Katowicka Hałda" lat="50.2413889" lon="18.9861111" boundingbox="50.2412889,50.2414889,18.9860111,18.9862111"> Katowicka Hałda, Załęska Hałda, Załęska Hałda-Brynów, Katowice, Silesian Voivodeship, Poland </result> <addressparts> <neighbourhood>Katowicka Hałda</neighbourhood> <suburb>Załęska Hałda</suburb> <city_district>Załęska Hałda-Brynów</city_district> <city>Katowice</city> <county>Katowice</county> <state>Silesian Voivodeship</state> <country>Poland</country> <country_code>pl</country_code> </addressparts> </reversegeocode>
It returns deep details, up to street (with
Remarks and details
This reverse geocoder supports
zoom parameter and it influences number and level of returned dataset. For example, above
zoom=16 will return most detailed information, up to
<road>, while setting
zoom=3 will return
1 will also return
<continent>, but at this level results are quite incorrect, as for above example — Katowice, Poland, Europe — it actually returns
Niemcy (Germany) as
Unia Europejska (European Union) as
Never heard of a continent called European Union! :>
The fastest way is to read entire location’s address from
<result> tag, even though it is long and some data are mixed. Building own location name from
<addressparts> tag’s elements might be difficult, if not impossible, because each query can return different sub-elements.
Keep also in mind that particular
<addressparts>‘s sub-elements might change for the very same location, when you change the zoom. For example, above mentioned query returns
gmina Rząśnia as
zoom is set to
powiat bełchatowski for the very same location, when
zoom is changed to
This is really strange and furthermore justifies, that using
<addressparts> might be hard or impossible and that using
<result> tag is the best / the only option.
GeoNames always returns only three elements and thus offers more “stable” results.
Also, zoom factor in GeoNames influences only kind of information returned and never number of elements returned. GeoNames always return three elements, if they’re available and less only, if there isn’t enough data to return.