1"use strict";(self.webpackChunkgeoapify_home=self.webpackChunkgeoapify_home||[]).push([[2085],{1499:function(e,n,t){t.r(n),t.d(n,{default:function(){return L}});var a=t(4506),s=t(8453),o=t(6540);function l(e){const n=Object.assign({p:"p",a:"a",strong:"strong",ul:"ul",li:"li",h2:"h2",code:"code",h3:"h3",h4:"h4",span:"span",em:"em"},(0,s.RP)(),e.components),{TableOfContent:t,FAQWithStructuredData:a}=n;return a||c("FAQWithStructuredData",!0),t||c("TableOfContent",!0),o.createElement(o.Fragment,null,o.createElement(n.p,null,"Reverse geocoding is the process of converting geographic coordinates (latitude and longitude) into human-readable addresses. It's an essential feature for location-based applications â from mapping tools and logistics systems to travel apps and data analysis workflows.\nYou can learn more about how it works in our article ",o.createElement(n.a,{href:"/what-is-reverse-geocoding/"},"What is Reverse Geocoding?")),"\n",o.createElement(n.p,null,"In this tutorial, you'll learn how to perform ",o.createElement(n.strong,null,"reverse geocoding in Python")," using the ",o.createElement(n.a,{href:"/reverse-geocoding-api/"},"Geoapify Reverse Geocoding API"),". Specifically, we will:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,"Introduce the Reverse Geocoding API and its capabilities"),"\n",o.createElement(n.li,null,"Show how to make API calls from Python"),"\n",o.createElement(n.li,null,"Explain how to handle batch reverse geocoding while respecting rate limits"),"\n",o.createElement(n.li,null,"Provide a ",o.createElement(n.a,{href:"https://github.com/geoapify/maps-api-code-samples/tree/main/python/reverse-geocoding",target:"_blank",rel:"nofollow"},"GitHub example")," you can download and integrate into your own project"),"\n"),"\n",o.createElement(n.p,null,"This guide is ideal for developers looking to turn geographic coordinates into useful address data efficiently and reliably."),"\n",o.createElement(t,{titles:[{label:"Reverse Geocoding API",id:"api"},{label:"Call API with Python",id:"call-api-with-python"},{label:"Batch calls in Python",id:"batch-calls-in-python"},{label:"Code Sample in GitHub",id:"github"},{label:"FAQ",id:"faq"}]}),"\n",o.createElement("div",{className:"place-delimiter"}),"\n",o.createElement("div",{className:"-mt-20 pt-20",id:"api"}),"\n",o.createElement(n.h2,null,"Reverse Geocoding API Overview"),"\n",o.createElement(n.p,null,"The ",o.createElement(n.a,{href:"/reverse-geocoding-api/"},"Geoapify Reverse Geocoding API")," allows you to convert geographic coordinates (latitude and longitude) into readable addresses or specific location elements such as city, street, or country. This is especially useful for mapping applications, geospatial analysis, and location-based services."),"\n",o.createElement(n.p,null,"If you're not sure how reverse geocoding differs from regular geocoding, check out our comparison: ",o.createElement(n.a,{href:"/geocoding-vs-reverse-geocoding/"},"Geocoding vs. Reverse Geocoding"),"."),"\n",o.createElement(n.p,null,o.createElement(n.strong,null,"Important:")," To use the script, youâll need a ",o.createElement(n.strong,null,"Geoapify API key"),". You can get a free API key by ",o.createElement(n.a,{href:"/"},"signing up on Geoapify.com")," â no credit card required."),"\n",o.createElement(n.p,null,"One of the key features of the API is the ",o.createElement(n.code,null,"type")," parameter, which lets you specify the ",o.createElement(n.strong,null,"location type")," you want to retrieve. This allows you to fine-tune the response to your needs and minimize unnecessary data."),"\n",o.createElement(n.h3,null,"Supported ",o.createElement(n.code,null,"type")," values:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,o.createElement(n.code,null,"country")," â Get the country name and code"),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"state")," â Get the state or administrative region"),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"city")," â Get the city or town"),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"postcode")," â Get the postal code"),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"street")," â Get the street name"),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"amenity")," â Get nearby amenities like buildings or landmarks"),"\n"),"\n",o.createElement(n.h3,null,"Examples"),"\n",o.createElement(n.h4,null,"Get Full Address from Latitude and Longitude"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`https://api.geoapify.com/v1/geocode/reverse?lat=52.21802590162346&lon=20.978425629505296&format=json&apiKey=YOUR_API_KEY`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1<path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">https://api.geoapify.com/v1/geocode/reverse?lat<span class="token operator">=</span><span class="token number">52.21802590162346</span><span class="token operator">&</span><span class="token assign-left variable">lon</span><span class="token operator">=</span><span class="token number">20.978425629505296</span><span class="token operator">&</span><span class="token assign-left variable">format</span><span class="token operator">=</span>json<span class="token operator">&</span><span class="token assign-left variable">apiKey</span><span class="token operator">=</span>YOUR_API_KEY</code></pre></div>'}})),"\n",o.createElement(n.p,null,'This request returns a complete address, including street, postcode, city, and country - "',o.createElement(n.em,null,"Biblioteka PW filia DS Babilon, KopiÅska 12/16, 02-315 Warsaw, Poland"),'"'),"\n",o.createElement(n.h4,null,"Get Only the Street Name"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`https://api.geoapify.com/v1/geocode/reverse?lat=52.21802590162346&lon=20.978425629505296&format=json&type=street&apiKey=YOUR_API_KEY`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">https://api.geoapify.com/v1/geocode/reverse?lat<span class="token operator">=</span><span class="token number">52.21802590162346</span><span class="token operator">&</span><span class="token assign-left variable">lon</span><span class="token operator">=</span><span class="token number">20.978425629505296</span><span class="token operator">&</span><span class="token assign-left variable">format</span><span class="token operator">=</span>json<span class="token operator">&</span><span class="token assign-left variable">type</span><span class="token operator">=</span>street<span class="token operator">&</span><span class="token assign-left variable">apiKey</span><span class="token operator">=</span>YOUR_API_KEY</code></pre></div>'}})),"\n",o.createElement(n.p,null,'Returns only the street name near the specified coordinates - "',o.createElement(n.em,null,"WÄgierska, 02-318 Warsaw, Poland"),'"'),"\n",o.createElement(n.h4,null,"Get the Postcode from Coordinates"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`https://api.geoapify.com/v1/geocode/reverse?lat=52.21802590162346&lon=20.978425629505296&type=postcode&apiKey=YOUR_API_KEY`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1<path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">https://api.geoapify.com/v1/geocode/reverse?lat<span class="token operator">=</span><span class="token number">52.21802590162346</span><span class="token operator">&</span><span class="token assign-left variable">lon</span><span class="token operator">=</span><span class="token number">20.978425629505296</span><span class="token operator">&</span><span class="token assign-left variable">type</span><span class="token operator">=</span>postcode<span class="token operator">&</span><span class="token assign-left variable">apiKey</span><span class="token operator">=</span>YOUR_API_KEY</code></pre></div>'}})),"\n",o.createElement(n.p,null,'This request returns only the postal code associated with the specified coordinates - "',o.createElement(n.em,null,"02-318 Warsaw"),'".'),"\n",o.createElement(n.h4,null,"Get the City from Coordinates"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`https://api.geoapify.com/v1/geocode/reverse?lat=52.21802590162346&lon=20.978425629505296&type=city&apiKey=YOUR_API_KEY`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">https://api.geoapify.com/v1/geocode/reverse?lat<span class="token operator">=</span><span class="token number">52.21802590162346</span><span class="token operator">&</span><span class="token assign-left variable">lon</span><span class="token operator">=</span><span class="token number">20.978425629505296</span><span class="token operator">&</span><span class="token assign-left variable">type</span><span class="token operator">=</span>city<span class="token operator">&</span><span class="token assign-left variable">apiKey</span><span class="token operator">=</span>YOUR_API_KEY</code></pre></div>'}})),"\n",o.createElement(n.p,null,"Returns the city name â in this case, ",o.createElement(n.em,null,"Warsaw"),"."),"\n",o.createElement(n.h3,null,"Response Example"),"\n",o.createElement(n.p,null,"Here's a simplified JSON response from a full reverse geocoding query for the provided coordinates:"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`{\n "results": [\n {\n "country": "Poland",\n "country_code": "pl",\n "state": "Masovian Voivodeship",\n "city": "Warsaw",\n "postcode": "02-318",\n "suburb": "Ochota",\n "quarter": "Stara Ochota",\n "iso3166_2": "PL-14",\n "datasource": {\n "sourcename": "openstreetmap",\n "attribution": "© OpenStreetMap contributors",\n "license": "Open Database License",\n "url": "https://www.openstreetmap.org/copyright"\n },\n "result_type": "postcode",\n "lon": 20.979253,\n "lat": 52.2175982,\n "distance": 73.74792796920609,\n "formatted": "02-318 Warsaw, Poland",\n "address_line1": "02-318 Warsaw",\n "address_line2": "Poland",\n "category": "administrative",\n "timezone": {\n "name": "Europe/Warsaw",\n "offset_STD": "
1+01:00",\n "offset_STD_seconds": 3600,\n "offset_DST": "+02:00",\n "offset_DST_seconds": 7200,\n "abbreviation_STD": "CET",\n "abbreviation_DST": "CEST"\n },\n "plus_code": "9G426X9H+2P",\n "plus_code_short": "6X9H+2P Warsaw, Masovian Voivodeship, Poland"\n }\n ],\n "query": {\n "lat": 52.21802590162346,\n "lon": 20.978425629505296,\n "plus_code": "9G426X9H+69"\n }\n}`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="json"><pre class="language-json"><code class="language-json"><span class="token punctuation">{</span>\n <span class="token property">"results"</span><span class="token operator">:</span> <span class="token punctuation">[</span>\n <span class="token punctuation">{</span>\n <span class="token property">"country"</span><span class="token operator">:</span> <span class="token string">"Poland"</span><span class="token punctuation">,</span>\n <span class="token property">"country_code"</span><span class="token operator">:</span> <span class="token string">"pl"</span><span class="token punctuation">,</span>\n <span class="token property">"state"</span><span class="token operator">:</span> <span class="token string">"Masovian Voivodeship"</span><span class="token punctuation">,</span>\n <span class="token property">"city"</span><span class="token operator">:</span> <span class="token string">"Warsaw"</span><span class="token punctuation">,</span>\n <span class="token property">"postcode"</span><span class="token operator">:</span> <span class="token string">"02-318"</span><span class="token punctuation">,</span>\n <span class="token property">"suburb"</span><span class="token operator">:</span> <span class="token string">"Ochota"</span><span class="token punctuation">,</span>\n <span class="token property">"quarter"</span><span class="token operator">:</span> <span class="token string">"Stara Ochota"</span><span class="token punctuation">,</span>\n <span class="token property">"iso3166_2"</span><span class="token operator">:</span> <span class="token string">"PL-14"</span><span class="token punctuation">,</span>\n <span class="token property">"datasource"</span><span class="token operator">:</span> <span class="token punctuation">{</span>\n <span class="token property">"sourcename"</span><span class="token operator">:</span> <span class="token string">"openstreetmap"</span><span class="token punctuation">,</span>\n <span class="token property">"attribution"</span><span class="token operator">:</span> <span class="token string">"© OpenStreetMap contributors"</span><span class="token punctuation">,</span>\n <span class="token property">"license"</span><span class="token operator">:</span> <span class="token string">"Open Database License"</span><span class="token punctuation">,</span>
1\n <span class="token property">"url"</span><span class="token operator">:</span> <span class="token string">"https://www.openstreetmap.org/copyright"</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token property">"result_type"</span><span class="token operator">:</span> <span class="token string">"postcode"</span><span class="token punctuation">,</span>\n <span class="token property">"lon"</span><span class="token operator">:</span> <span class="token number">20.979253</span><span class="token punctuation">,</span>\n <span class="token property">"lat"</span><span class="token operator">:</span> <span class="token number">52.2175982</span><span class="token punctuation">,</span>\n <span class="token property">"distance"</span><span class="token operator">:</span> <span class="token number">73.74792796920609</span><span class="token punctuation">,</span>\n <span class="token property">"formatted"</span><span class="token operator">:</span> <span class="token string">"02-318 Warsaw, Poland"</span><span class="token punctuation">,</span>\n <span class="token property">"address_line1"</span><span class="token operator">:</span> <span class="token string">"02-318 Warsaw"</span><span class="token punctuation">,</span>\n <span class="token property">"address_line2"</span><span class="token operator">:</span> <span class="token string">"Poland"</span><span class="token punctuation">,</span>\n <span class="token property">"category"</span><span class="token operator">:</span> <span class="token string">"administrative"</span><span class="token punctuation">,</span>\n <span class="token property">"timezone"</span><span class="token operator">:</span> <span class="token punctuation">{</span>\n <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"Europe/Warsaw"</span><span class="token punctuation">,</span>\n <span class="token property">"offset_STD"</span><span class="token operator">:</span> <span class="token string">"+01:00"</span><span class="token punctuation">,</span>\n <span class="token property">"offset_STD_seconds"</span><span class="token operator">:</span> <span class="token number">3600</span><span class="token punctuation">,</span>\n <span class="token property">"offset_DST"</span><span class="token operator">:</span> <span class="token string">"+02:00"</span><span class="token punctuation">,</span>\n <span class="token property">"offset_DST_seconds"</span><span class="token operator">:</span> <span class="token number">7200</span><span class="token punctuation">,</span>\n <span class="token property">"abbreviation_STD"</span><span class="token operator">:</span> <span class="token string">"CET"</span><span class="token punctuation">,</span>\n <span class="token property">"abbreviation_DST"</span><span class="token operator">:</span> <span class="token string">"CEST"</span>\n <span class="token punctuation">}</span><span class="token punctuation">,</span>\n <span class="token property">"plus_code"</span><span class="token operator">:</span> <span class="token string">"9G426X9H+2P"</span><span class="token punctuation">,</span>\n <span class="token property">"plus_code_short"</span><span class="token operator">:</span> <span class="token string">"6X9H+2P Warsaw, Masovian Voivodeship, Poland"</span>\n <span class="token punctuation">}</span>\n <span class="token punctuation">]</span><span class="token punctuation">,</span>\n <span class="token property">"query"</span><span class="token operator">:</span> <span class="token punctuation">{</span>\n <span class="token property">"lat"</span><span class="token operator">:</span> <span class="token number">52.21802590162346</span><span class="token punctuation">,</span>\n <span class="token property">"lon"</span><span class="token operator">:</span> <span class="token number">20.978425629505296</span><span class="token punctuation">,</span>\n <span class="token property">"plus_code"</span><span class="token operator">:</span> <span class="token string">"9G426X9H+69"</span>\n <span class="token punctuation">}</span>\n<span class="token punctuation">}</span></code></pre></div>'}})),"\n",o.createElement(n.p,null,"You can extract the desired fields from the ",o.
1createElement(n.code,null,"properties")," object, depending on whether you need a full address, a specific element like the street name, or nearby amenities."),"\n",o.createElement(n.p,null,"The Geoapify Reverse Geocoding API also includes a ",o.createElement(n.code,null,"distance")," field in the response. This value represents the distance (in meters) between the ",o.createElement(n.strong,null,"input coordinates")," you provided and the ",o.createElement(n.strong,null,"location")," that was matched and returned by the API."),"\n",o.createElement(n.p,null,"This is helpful because:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,"It lets you assess ",o.createElement(n.strong,null,"how close")," the returned result is to your input coordinates."),"\n",o.createElement(n.li,null,"If you're dealing with ",o.createElement(n.strong,null,"approximate or noisy GPS data"),", you can use the distance to ",o.createElement(n.strong,null,"filter or validate")," results."),"\n",o.createElement(n.li,null,"For batch processing, you can ",o.createElement(n.strong,null,"rank multiple results")," based on proximity or discard results that exceed a specific distance threshold."),"\n"),"\n",o.createElement("div",{className:"place-delimiter"}),"\n",o.createElement("div",{className:"-mt-20 pt-20",id:"call-api-with-python"}),"\n",o.createElement(n.h2,null,"How to Call the Reverse Geocoding API with Python"),"\n",o.createElement(n.p,null,"To call the Geoapify Reverse Geocoding API in Python, you can use the popular ",o.createElement(n.a,{href:"https://pypi.org/project/requests/",target:"_blank",rel:"nofollow"},o.createElement(n.code,null,"requests"))," library to send HTTP GET requests. Below is a reusable function that demonstrates how to query the API and handle different response types."),"\n",o.createElement(n.h3,null,"Reverse Geocoding Python Code Example"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`import requests\nimport logging\n\nlogger = logging.getLogger(__name__)\n\nGEOAPIFY_API_URL = "https://api.geoapify.com/v1/geocode/reverse"\n\ndef reverse_geocode(api_key, lat, lon, country_filter=None, result_type=None, output_format="json"):\n params = {\n \'lat\': lat,\n \'lon\': lon,\n \'apiKey\': api_key,\n \'format\': output_format\n }\n if country_filter:\n params[\'filter\'] = \'countrycode:\' + country_filter\n if result_type:\n params[\'type\'] = result_type\n\n try:\n response = requests.get(GEOAPIFY_API_URL, params=params)\n if response.status_code == 200:\n data = response.json()\n if \'results\' in data:\n return data[\'results\'][0]\n elif \'features\' in data:\n return data[\'features\'][0]\n else:\n return {}\n elif response.status_code == 429:\n logger.warning("Rate limit exceeded. Too many requests.")\n return {}\n else:\n logger.error(f"Error: {response.status_code} for coordinates: ({lat}, {lon})")\n return {}\n except Exception as e:\n logger.error(f"Exception occurred: {e} for coordinates: ({lat}, {lon})")\n return {}`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1<path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="python"><pre class="language-python"><code class="language-python"><span class="token keyword">import</span> requests\n<span class="token keyword">import</span> logging\n\nlogger <span class="token operator">=</span> logging<span class="token punctuation">.</span>getLogger<span class="token punctuation">(</span>__name__<span class="token punctuation">)</span>\n\nGEOAPIFY_API_URL <span class="token operator">=</span> <span class="token string">"https://api.geoapify.com/v1/geocode/reverse"</span>\n\n<span class="token keyword">def</span> <span class="token function">reverse_geocode</span><span class="token punctuation">(</span>api_key<span class="token punctuation">,</span> lat<span class="token punctuation">,</span> lon<span class="token punctuation">,</span> country_filter<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> result_type<span class="token operator">=</span><span class="token boolean">None</span><span class="token punctuation">,</span> output_format<span class="token operator">=</span><span class="token string">"json"</span><span class="token punctuation">)</span><span class="token punctuation">:</span>\n params <span class="token operator">=</span> <span class="token punctuation">{</span>\n <span class="token string">\'lat\'</span><span class="token punctuation">:</span> lat<span class="token punctuation">,</span>\n <span class="token string">\'lon\'</span><span class="token punctuation">:</span> lon<span class="token punctuation">,</span>\n <span class="token string">\'apiKey\'</span><span class="token punctuation">:</span> api_key<span class="token punctuation">,</span>\n <span class="token string">\'format\'</span><span class="token punctuation">:</span> output_format\n <span class="token punctuation">}</span>\n <span class="token keyword">if</span> country_filter<span class="token punctuation">:</span>\n params<span class="token punctuation">[</span><span class="token string">\'filter\'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">\'countrycode:\'</span> <span class="token operator">+</span> country_filter\n <span class="token keyword">if</span> result_type<span class="token punctuation">:</span>\n params<span class="token punctuation">[</span><span class="token string">\'type\'</span><span class="token punctuation">]</span> <span class="token operator">=</span> result_type\n\n <span class="token keyword">try</span><span class="token punctuation">:</span>\n response <span class="token operator">=</span> requests<span class="token punctuation">.</span>get<span class="token punctuation">(</span>GEOAPIFY_API_URL<span class="token punctuation">,</span> params<span class="token operator">=</span>params<span class="token punctuation">)</span>\n <span class="token keyword">if</span> response<span class="token punctuation">.</span>status_code <span class="token operator">==</span> <span class="token number">200</span><span class="token punctuation">:</span>\n data <span class="token operator">=</span> response<span class="token punctuation">.</span>json<span class="token punctuation">(</span><span class="token punctuation">)</span>\n <span class="token keyword">if</span> <span class="token string">
1\'results\'</span> <span class="token keyword">in</span> data<span class="token punctuation">:</span>\n <span class="token keyword">return</span> data<span class="token punctuation">[</span><span class="token string">\'results\'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>\n <span class="token keyword">elif</span> <span class="token string">\'features\'</span> <span class="token keyword">in</span> data<span class="token punctuation">:</span>\n <span class="token keyword">return</span> data<span class="token punctuation">[</span><span class="token string">\'features\'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span>\n <span class="token keyword">else</span><span class="token punctuation">:</span>\n <span class="token keyword">return</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>\n <span class="token keyword">elif</span> response<span class="token punctuation">.</span>status_code <span class="token operator">==</span> <span class="token number">429</span><span class="token punctuation">:</span>\n logger<span class="token punctuation">.</span>warning<span class="token punctuation">(</span><span class="token string">"Rate limit exceeded. Too many requests."</span><span class="token punctuation">)</span>\n <span class="token keyword">return</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>\n <span class="token keyword">else</span><span class="token punctuation">:</span>\n logger<span class="token punctuation">.</span>error<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f"Error: </span><span class="token interpolation"><span class="token punctuation">{</span>response<span class="token punctuation">.</span>status_code<span class="token punctuation">}</span></span><span class="token string"> for coordinates: (</span><span class="token interpolation"><span class="token punctuation">{</span>lat<span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span>lon<span class="token punctuation">}</span></span><span class="token string">)"</span></span><span class="token punctuation">)</span>\n <span class="token keyword">return</span> <span class="token punctuation">{</span><span class="token punctuation">}</span>\n <span class="token keyword">except</span> Exception <span class="token keyword">as</span> e<span class="token punctuation">:</span>\n logger<span class="token punctuation">.</span>error<span class="token punctuation">(</span><span class="token string-interpolation"><span class="token string">f"Exception occurred: </span><span class="token interpolation"><span class="token punctuation">{</span>e<span class="token punctuation">}</span></span><span class="token string"> for coordinates: (</span><span class="token interpolation"><span class="token punctuation">{</span>lat<span class="token punctuation">}</span></span><span class="token string">, </span><span class="token interpolation"><span class="token punctuation">{</span>lon<span class="token punctuation">}</span></span><span class="token string">)"</span></span><span class="token punctuation">)</span>\n <span class="token keyword">return</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></code></pre></div>'}})),"\n",o.createElement(n.h3,null,"How It Works"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,"\n",o.createElement(n.p,null,"The function accepts coordinates (",o.createElement(n.code,null,"lat"),", ",o.createElement(n.code,null,"lon"),"), your API key, and optional parameters:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,o.createElement(n.code,null,"country_filter")," â to restrict results to a
1specific country."),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"result_type")," â to request a specific location type (e.g. ",o.createElement(n.code,null,"street"),", ",o.createElement(n.code,null,"city"),", ",o.createElement(n.code,null,"postcode"),")."),"\n",o.createElement(n.li,null,o.createElement(n.code,null,"output_format")," â defaults to ",o.createElement(n.code,null,'"json"'),", but you can change it to ",o.createElement(n.code,null,'"geojson"')," if needed."),"\n"),"\n"),"\n",o.createElement(n.li,null,"\n",o.createElement(n.p,null,"It builds a request to the API with those parameters and parses the result."),"\n"),"\n",o.createElement(n.li,null,"\n",o.createElement(n.p,null,"It handles:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,o.createElement(n.strong,null,"Valid results")," (",o.createElement(n.code,null,"results")," or ",o.createElement(n.code,null,"features")," fields in the response),"),"\n",o.createElement(n.li,null,o.createElement(n.strong,null,"Rate limit errors")," (",o.createElement(n.code,null,"429 Too Many Requests"),"), and"),"\n",o.createElement(n.li,null,o.createElement(n.strong,null,"Unexpected exceptions")," with helpful logging."),"\n"),"\n"),"\n"),"\n",o.createElement(n.p,null,"This structure makes it easy to integrate into larger applications and handle a variety of use cases with minimal changes."),"\n",o.createElement("div",{className:"place-delimiter"}),"\n",o.createElement("div",{className:"-mt-20 pt-20",id:"batch-calls-in-python"}),"\n",o.createElement(n.h2,null,"Reverse Geocoding Multiple Coordinates"),"\n",o.createElement(n.p,null,"The previous example shows how to reverse geocode a single coordinate. However, in practice, you often need to reverse geocode ",o.createElement(n.strong,null,"a list of coordinates")," â for example, GPS traces, delivery stops, or datasets with location data."),"\n",o.createElement(n.p,null,"When sending many API requests, itâs important to ",o.createElement(n.strong,null,"respect rate limits")," to avoid overloading the API or being temporarily throttled. Geoapifyâs Reverse Geocoding API has soft rate limits, which means brief spikes are tolerated, but consistent overuse may result in slower responses or blocked access. You can find tips on handling rate limits in our ",o.createElement(n.a,{href:"/tutorial/geocoding-python/#api-limits"},"Geocoding in Python tutorial â API Limits section"),"."),"\n",o.createElement(n.h3,null,"Sending Requests in Batches with Python"),"\n",o.createElement(n.p,null,"To efficiently process multiple coordinates, you can group them into batches and use ",o.createElement(n.a,{href:"https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor",target:"_blank",rel:"nofollow"},o.createElement(n.code,null,"ThreadPoolExecutor"))," from the ",o.createElement(n.code,null,"concurrent.futures")," module to send parallel requests. Add a short ",o.createElement(n.code,null,"sleep")," between batches to control the request rate."),"\n",o.createElement(n.p,null,"Hereâs how it works:"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED\nfrom time import sleep\nimport json\n\n# Request results asynchronously for each batch\ntasks = []\nwith ThreadPoolExecutor(max_workers=10) as executor:\n for batch in coordinates:\n logger.info(batch)\n for coord in batch:\n if order == \'latlon\':\n lat, lon = map(float, coord.split(\',\'))\n elif order == \'lonlat\':\n lon, lat = map(float, coord.split(\',\'))\n tasks.append(\n executor.submit(reverse_geocode, api_key, lat, lon, country_filter, result_type, output_format)\n )\n sleep(1) # Wait 1 second between batches to respect RPS limits\n\n# Wait for all tasks to complete\nwait(tasks, return_when=ALL_COMPLETED)`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1<path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="python"><pre class="language-python"><code class="language-python"><span class="token keyword">from</span> concurrent<span class="token punctuation">.</span>futures <span class="token keyword">import</span> ThreadPoolExecutor<span class="token punctuation">,</span> wait<span class="token punctuation">,</span> ALL_COMPLETED\n<span class="token keyword">from</span> time <span class="token keyword">import</span> sleep\n<span class="token keyword">import</span> json\n\n<span class="token comment"># Request results asynchronously for each batch</span>\ntasks <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>\n<span class="token keyword">with</span> ThreadPoolExecutor<span class="token punctuation">(</span>max_workers<span class="token operator">=</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token keyword">as</span> executor<span class="token punctuation">:</span>\n <span class="token keyword">for</span> batch <span class="token keyword">in</span> coordinates<span class="token punctuation">:</span>\n logger<span class="token punctuation">.</span>info<span class="token punctuation">(</span>batch<span class="token punctuation">)</span>\n <span class="token keyword">for</span> coord <span class="token keyword">in</span> batch<span class="token punctuation">:</span>\n <span class="token keyword">if</span> order <span class="token operator">==</span> <span class="token string">\'latlon\'</span><span class="token punctuation">:</span>\n lat<span class="token punctuation">,</span> lon <span class="token operator">=</span> <span class="token builtin">map</span><span class="token punctuation">(</span><span class="token builtin">float</span><span class="token punctuation">,</span> coord<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">\',\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>\n <span class="token keyword">elif</span> order <span class="token operator">==</span> <span class="token string">\'lonlat\'</span><span class="token punctuation">:</span>\n lon<span class="token punctuation">,</span> lat <span class="token operator">=</span> <span class="token builtin">map</span><span class="token punctuation">(</span><span class="token builtin">float</span><span class="token punctuation">,</span> coord<span class="token punctuation">.</span>split<span class="token punctuation">(</span><span class="token string">\',\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span>\n tasks<span class="token punctuation">.</span>append<span class="token punctuation">(</span>\n executor<span class="token punctuation">.</span>submit<span class="token punctuation">(</span>reverse_geocode<span class="token punctuation">,</span> api_key<span class="token punctuation">,</span> lat<span class="token punctuation">,</span> lon<span class="token punctuation">,</span> country_filter<span class="token punctuation">,</span> result_type<span class="token punctuation">,</span> output_format<span class="token punctuation">)</span>\n <span class="token punctuation">)</span>\n sleep<span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment"># Wait 1 second between batches to respect RPS limits</span>\n\n<span class="token comment"># Wait for all tasks to complete</span>\nwait<span class="token punctuation">(</span>tasks<span class="token punctuation">,</span> return_when<span class="token operator">=</span>ALL_COMPLETED<span class="token punctuation">)</span></code></pre></div>'}})),"\n",o.createElement(n.h3,null,"Explanation"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor",target:"_blank",rel:"nofollow"},o.createElement(n.code,null,"ThreadPoolExecutor"))," manages concurrent requests to speed up processing."),"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"https://docs.python.org/3/library/time.html#time.sleep",target:"_blank",rel:"nofollow"},o.createElement(n.code,null,"sleep()"))," pauses execution between batches to help stay within rate limits."),"\n",o.createElement(n.li,null,"Results are gathered after all requests complete using ",o.createElement(n.a,{href:"https://docs.python.org/3/library/concurrent.futures.html#concurrent.futures.wait",target:"_blank",rel:"nofollow"},o.createElement(n.code,null,"wait()")),"."),"\n"),"\n",o.createElement(n.p,null,"This method allows you to scale your reverse geocoding process while being API-friendly and efficie
1nt."),"\n",o.createElement("div",{className:"place-delimiter"}),"\n",o.createElement("div",{className:"-mt-20 pt-20",id:"github"}),"\n",o.createElement(n.h2,null,"GitHub Example: Reverse Geocoding in Python"),"\n",o.createElement(n.p,null,"To help you get started quickly, weâve prepared a working example in our ",o.createElement(n.a,{href:"https://github.com/geoapify/maps-api-code-samples/blob/main/python/reverse-geocoding/",target:"_blank",rel:"nofollow"},"Geoapify Maps API Code Samples repository"),". The script demonstrates how to reverse geocode a list of coordinates and write the results to a file."),"\n",o.createElement(n.h3,null,"Setup Instructions"),"\n",o.createElement(n.p,null,o.createElement(n.strong,null,"1. Clone the Repository")),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`git clone https://github.com/geoapify/maps-api-code-samples.git\ncd maps-api-code-samples/python/`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash"><span class="token function">git</span> clone https://github.com/geoapify/maps-api-code-samples.git\n<span class="token builtin class-name">cd</span> maps-api-code-samples/python/</code></pre></div>'}})),"\n",o.createElement(n.p,null,o.createElement(n.strong,null,"2. Create a Virtual Environment (Optional)")),"\n",o.createElement(n.p,null,"We recommend using a virtual environment to manage dependencies cleanly:"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">python <span class="token parameter variable">-m</span> venv <span class="token function">env</span>\n<span class="token builtin class-name">source</span> env/bin/activate <span class="token comment"># On Windows: env\\Scripts\\activate</span></code></pre></div>'}})),"\n",o.createElement(n.p,null,o.createElement(n.strong,null,"3. Install Dependencies")),"\n",o.createElement(n.p,null,"Install required packages using ",o.createElement(n.code,null,"pip"),":"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`pip install requests`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
1<path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash">pip <span class="token function">install</span> requests</code></pre></div>'}})),"\n",o.createElement(n.h3,null,"Running the Reverse Geocoding Script"),"\n",o.createElement(n.p,null,"Once dependencies are installed, navigate to the reverse geocoding folder and run the script:"),"\n",o.createElement("div",{className:"width-default"},o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-remark-copy-button-container">\n <button\n class="gatsby-remark-copy-button"\n onClick="copyToClipboard(`cd reverse-geocoding\npython reverse_geocode.py --api_key YOUR_API_KEY --input input.txt --output output.ndjson --order latlon`, this)"\n >\n <svg class="copy-icon" width="16" height="16" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512">\x3c!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--\x3e<path fill="#FFFFFF" d="M384 336H192c-8.8 0-16-7.2-16-16V64c0-8.8 7.2-16 16-16l140.1 0L400 115.9V320c0 8.8-7.2 16-16 16zM192 384H384c35.3 0 64-28.7 64-64V115.9c0-12.7-5.1-24.9-14.1-33.9L366.1 14.1c-9-9-21.2-14.1-33.9-14.1H192c-35.3 0-64 28.7-64 64V320c0 35.3 28.7 64 64 64zM64 128c-35.3 0-64 28.7-64 64V448c0 35.3 28.7 64 64 64H256c35.3 0 64-28.7 64-64V416H272v32c0 8.8-7.2 16-16 16H64c-8.8 0-16-7.2-16-16V192c0-8.8 7.2-16 16-16H96V128H64z"/></svg><svg class="success-icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path fill="#fff" d="M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>\n </button>\n </div>'}}),o.createElement(n.span,{dangerouslySetInnerHTML:{__html:'<div class="gatsby-highlight" data-language="bash"><pre class="language-bash"><code class="language-bash"><span class="token builtin class-name">cd</span> reverse-geocoding\npython reverse_geocode.py <span class="token parameter variable">--api_key</span> YOUR_API_KEY <span class="token parameter variable">--input</span> input.txt <span class="token parameter variable">--output</span> output.ndjson <span class="token parameter variable">--order</span> latlon</code></pre></div>'}})),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,"The script ",o.createElement(n.strong,null,"reads coordinates from ",o.createElement(n.code,null,"input.txt"))," (one per line)."),"\n",o.createElement(n.li,null,"It performs reverse geocoding using the Geoapify API."),"\n",o.createElement(n.li,null,"The results are saved to ",o.createElement(n.strong,null,o.createElement(n.code,null,"output.ndjson"))," in ",o.createElement(n.a,{href:"https://github.com/ndjson/ndjson-spec",target:"_blank",rel:"nofollow"},"NDJSON")," format â one JSON object per line, ideal for large or streamed datasets."),"\n"),"\n",o.createElement(n.p,null,"You can modify the ",o.createElement(n.code,null,"--order")," parameter to match your coordinate format (",o.createElement(n.code,null,"latlon")," or ",o.createElement(n.code,null,"lonlat"),") and optionally adjust filtering options in the script."),"\n",o.createElement(n.p,null,"This example is a great starting point for integrating reverse geocoding into your own Python-based tools or data processing pipelines."),"\n",o.createElement(n.h2,null,"Conclusion"),"\n",o.createElement(n.p,null,"Reverse geocoding is a key component in many location-based applications, helping you transform raw geographic coordinates into meaningful address data. With the Geoapify Reverse Geocoding API and a few lines of Python code, you can easily retrieve full addresses or specific location elements like streets, postcodes, or cities."),"\n",o.createElement(n.p,null,"In this tutorial, you learned how to:"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,"Call the Reverse Geocoding API from Python"),"\n",o.createElement(n.li,null,"Handle batch requests efficie
1ntly while respecting rate limits"),"\n",o.createElement(n.li,null,"Use filtering options like ",o.createElement(n.code,null,"type")," and ",o.createElement(n.code,null,"countrycode")),"\n",o.createElement(n.li,null,"Work with real-world code examples, including one from GitHub"),"\n"),"\n",o.createElement(n.p,null,"Ready to get started? ",o.createElement(n.a,{href:"https://www.geoapify.com/",target:"_blank",rel:"nofollow"},"Sign up for a free API key")," and try it with your own data â no credit card required."),"\n",o.createElement(n.h3,null,"Read more"),"\n",o.createElement(n.ul,null,"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"/geocoding-api/"},"Geoapify Geocoding API")),"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"/tools/reverse-geocoding-online/"},"Reverse Geocoding Online Tool")),"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"/geocode-millions-of-records-efficiently/"},"How to Geocode Millions of Records Efficiently")),"\n",o.createElement(n.li,null,o.createElement(n.a,{href:"/tutorial/reverse-geocoding-javascript-tutorial/"},"Reverse Geocoding JavaScript Tutorial")),"\n"),"\n",o.createElement("div",{className:"place-delimiter"}),"\n",o.createElement("div",{className:"-mt-20 pt-20",id:"faq"}),"\n",o.createElement(a,{title:"FAQ",questions:[{question:"What is reverse geocoding?",answer:"Reverse geocoding is the process of converting geographic coordinates (latitude and longitude) into a human-readable address or location description, such as a city name, street, or postal code."},{question:"How do I perform reverse geocoding in Python?",answer:"You can use the Geoapify Reverse Geocoding API along with the Python 'requests' library to send coordinate-based queries and retrieve address data. This tutorial provides complete code examples and setup instructions."},{question:"Can I reverse geocode multiple coordinates at once?",answer:"Yes. You can process a list of coordinates in batches using Pythonâs ThreadPoolExecutor to send requests in parallel while respecting API rate limits. Our GitHub example demonstrates this approach in detail."},{question:"What is the 'type' parameter used for?",answer:"The 'type' parameter lets you specify which part of the address to return â for example, 'street', 'city', or 'postcode'. This helps reduce response size and extract only the data you need."},{question:"Do I need an API key to use the Geoapify Reverse Geocoding API?",answer:"Yes. You can get a free API key by signing up at <a href='https://www.geoapify.com/' target='_blank' rel='noopener noreferrer'>www.geoapify.com</a>. No credit card is required."},{question:"What happens if I exceed the rate limit?",answer:"If you exceed the limit (5 requests per second on the Free plan), you may receive a 429 Too Many Requests error. To avoid this, space out requests and follow the guidelines in our <a href='/tutorial/geocoding-python/#api-limits' target='_blank'>API rate limit section</a>."},{question:"Where can I find the full reverse geocoding example in Python?",answer:"You can find a complete working example with input/output file support on <a href='https://github.com/geoapify/maps-api-code-samples/tree/main/python/reverse-geocoding' target='_blank' rel='noopener noreferrer'>GitHub</a>."}]}))}var p=function(e={}){const{wrapper:n}=Object.assign({},(0,s.RP)(),e.components);return n?o.createElement(n,e,o.createElement(l,e)):l(e)};function c(e,n){throw new Error("Expected "+(n?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}var r=t(4794),i=t(5588),u=t(8154),m=t(1574),d=t(7127),g=t(1543),h=t(3537),k=t(7339),f=t(2992),y=t(3481),w=t(9911),v=t(9856),b=t(529),E=t(8818),_=t(1435),q=t(2389),H=t(118),I=t(2833),x=t(9816),T=t(3960),P=t(5898);const A={Link:r.Link,SplitSection:y.A,BackgroundPanel:w.A,Card:v.A,Button:b.A,ButtonGroup:E.A,Banner:_.A,HowToStructuredData:q.A,FAQWithStructuredData:H.A,InputCheckbox:I.A,TryGeolocation:x.A,JSONTree:m.d,TableOfContent:T.A,PageList:P.A},F=({data:{post:e,logo:n,siteData:t,postFormattedData:l},children:p,pageContext:{modifiedTime:c}})=>{const r=e.frontmatter.featuredImage?e.frontmatter.featuredImage.childImageSharp.original:{},m=e.frontmatter.twitterImage2x1?e.frontmatter.twitterImage2x1.childImageSharp.original:{},y=e.frontmatter.languages?e.frontmatter.languages.map((e=>h.A.find((n=>n.id===e)))):[],w=y?y.map((e=>e.label)):null,v=k.A.find((n=>n.id===e.frontmatter.group))||{label:"Geoapify"},b=[e.frontmatter.image1x1,e.frontmatter.image4x3,e.frontmatter.image16x9].filter((e=>!!e)).map((e=>e.childImageSharp.original.src)),E=l.frontmatter.featuredImage?l.frontmatter.featuredImage.childImageSharp.gatsbyImageData:null,_="home"===e.frontmatter.slug.split("/").join("")?"https://www.geoapify.com/":`https://www.geoapify.com/${e.frontmatter.slug}/`;return o.createElement(o.Fragment,null,o.createElement(u.m,null,o.createElement("link",{rel:"canonical",href:_,"data-baseprotocol":"https:","data-basehost":"www.geoapify.com"})),o.createElement(g.A,{webpageTitle:e.frontmatter.title_60,webpageDescription:e.frontmatter.description_120,slug:e.frontmatter.slug,imageSrc:r.src,imageWidth:r.width,imageHeight:r.height,imageAlt:e.frontmatter.featuredImageAlt_12
10,ogType:"article",twitterImageSrc:m.src,twitterTitle:e.frontmatter.twitterTitle_70,twitterImageAlt:e.frontmatter.twitterImageAlt_420,twitterDescription:e.frontmatter.twitterDescription_200,articleSection:"Geo information systems (GIS)",articleTags:["tutorial",v.label].concat((0,a.A)(w)),created:e.frontmatter.date,modified:c}),o.createElement(f.A,{geoapifySlogan:t.siteMetadata.slogan,companyName:t.siteMetadata.company,logoSrc:n.childImageSharp.gatsbyImageData.src,logoWidth:n.childImageSharp.gatsbyImageData.width,logoHeight:n.childImageSharp.gatsbyImageData.height,slug:e.frontmatter.slug,articleName:e.frontmatter.title_60,articleHeadline:e.frontmatter.headline_110,published:e.frontmatter.date,modified:c,images:b}),o.createElement(d.A,null,o.createElement("article",{className:"geoapify-post"},o.createElement("header",{className:"geoapify-post-header"},o.createElement("div",{className:"geoapify-post-meta"},o.createElement("span",null,l.frontmatter.date),o.createElement("span",{className:"mx-1"}," / "),o.createElement("span",null,"by Geoapify"),o.createElement("span",{className:"ml-1"}," / in "),o.createElement("span",null,o.createElement("a",{href:"/tutorials/"},"Tutorials"))),o.createElement("h1",null,e.frontmatter.title),e.frontmatter.subtitle?o.createElement("h2",{className:"text-2xl text-gray-700 mx-2 font-light"},e.frontmatter.subtitle):null,E?o.createElement("div",{className:"geoapify-post-featured-image"},o.createElement(i.G,{image:E,alt:e.frontmatter.featuredImageAlt_120})):null,e.frontmatter.featuredImageAlt_120?o.createElement("div",{className:"text-center mt-2 mb-10 text-sm italic text-gray-700",dangerouslySetInnerHTML:{__html:e.frontmatter.featuredImageAlt_120}}):o.createElement("div",{className:"mb-10"})),o.createElement("section",{className:"geoapify-post-body"},o.createElement(s.xA,{components:A},p))),o.createElement("div",{className:"post-navigation"},o.createElement("div",{className:"post-navigation-buttons flex flex-col md:flex-row"},o.createElement("div",{className:"previous-post"},o.createElement("a",{href:"/tutorials/",rel:"prev"},o.createElement("div",{className:"previous"},o.createElement("span",{className:"chevron lnr lnr-chevron-left"}),o.createElement("div",{className:"title"},o.createElement("span",{className:"meta"},"Back to"),o.createElement("span",{className:"post-title"},"How-tos and Tutorials")))))))))};function L(e){return o.createElement(F,e,o.createElement(p,e))}},2389:function(e,n,t){var a=t(6540),s=t(8154);n.A=({name:e,description:n,supplies:t,tools:o,steps:l})=>{const p={"@context":"https://schema.org","@type":"HowTo",name:e,description:n,steps:l.map((e=>({"@type":"HowToStep",name:e.name,url:e.url,itemListElement:e.items.map((e=>({"@type":"HowToTip",text:e})))})))};return t&&t.length&&(p.supply=t.map((e=>({"@type":"HowToSupply",name:e})))),o&&o.length&&(p.tools=o.map((e=>({"@type":"HowToTool",name:e})))),a.createElement(s.m,null,a.createElement("script",{type:"application/ld+json"},JSON.stringify(p)))}},2992:function(e,n,t){var a=t(6540),s=t(8154);n.A=({companyName:e,geoapifySlogan:n,logoSrc:t,logoWidth:o,logoHeight:l,slug:p,articleName:c,articleHeadline:r,published:i,modified:u,images:m})=>{const d={"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.geoapify.com/#organization",name:e,url:"https://www.geoapify.com/",email:"[email protected]",brand:"Geoapify Location Platform",sameAs:["https://www.facebook.com/pg/Geoapify","https://www.linkedin.com/company/geoapify","https://twitter.com/Geoapify"],logo:{"@type":"ImageObject","@id":"https://www.geoapify.com/#logo",url:t,width:o,height:l,caption:e},slogan:n,image:{"@id":"https://www.geoapify.com/#logo"}}]},g={"@type":"Article","@id":`https://www.geoapify.com/${p}/#article`,mainEntityOfPage:`https://www.geoapify.com/${p}/`,name:c,headline:r,inLanguage:"en-US",publisher:{"@id":"https://www.geoapify.com/#organization"},author:{"@id":"https://www.geoapify.com/#organization"},datePublished:i,dateModified:u};return m&&(g.image=m),d["@graph"].push(g),a.createElement(s.m,null,a.createElement("script",{type:"application/ld+json"},JSON.stringify(d)))}}
1,3537:function(e,n){n.A=[{id:"javascript",label:"JavaScript"},{id:"angular",label:"Angular"},{id:"react",label:"React JS"},{id:"java",label:"Java"},{id:"c#",label:"C#"},{id:"r",label:"R language"},{id:"python",label:"Python"},{id:"nocode",label:"No code"}]},7339:function(e,n){n.A=[{id:"maps",label:"Maps"},{id:"geocoding",label:"Geocoding & Geolocation"},{id:"routing",label:"Routes & Optimization"},{id:"isoline",label:"Isochrones & isodistances"},{id:"places",label:"Places & Details"}]},9816:function(e,n,t){var a=t(6540);n.A=()=>{const{0:e,1:n}=(0,a.useState)(0),t=e=>{n(e)},s=e=>{let n;switch(e.code){case e.PERMISSION_DENIED:n="User denied the request for Geolocation.";break;case e.POSITION_UNAVAILABLE:n="Location information is unavailable.";break;case e.TIMEOUT:n="The request to get user location timed out.";break;case e.UNKNOWN_ERROR:default:n="An unknown error occurred."}t(`Error occured: ${n}`)},o=e=>{t(`Your geolocation: latitude: ${e.coords.latitude}, longitude: ${e.coords.longitude}`)};return a.createElement(a.Fragment,null,a.createElement("button",{onClick:()=>{const e={maximumAge:1e3,timeout:2e3,enableHighAccuracy:!0};navigator.geolocation?navigator.geolocation.getCurrentPosition(o,s,e):t("Geolocation is not supported by this browser.")},className:"border-solid border-2 border-indigo-300 rounded p-3 text-gray-800",type:"button"},"Try Geolocation API"),e?a.createElement("div",{className:"mt-2 text-indigo-700"},e):"")}}}]); 2//# sourceMappingURL=component---src-template-tutorial-post-js-content-file-path-src-tutorials-geocoding-reverse-python-index-mdx-760199f1bbe2018072ed.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.