Working with the Nominatim API

In this particular case, we are going to use OSM's Nominatim service. Its API is simple, free, does not require authorization, and has a relatively open license. Moreover, as OSM is open source, we theoretically can add and improve its content, if that is necessary for our project.

In order to work with an API, we first need to read its documentation. Often, documentation includes example snippets of code to use with the service in question—the code is usually in Python. Nominatim's documentation can be found at nominatim.openstreetmap.org. According to it, to get information for a given address, we should send a request to the following URL:

https://nominatim.openstreetmap.org/search?

All our parameters—the address, response format, geographic limitations, and so on—need to be added using standard URL escaping (don't worry—Python will take care of it for us). For example, to receive information on the Eiffel Tower in Paris as a JSON object, you could use the following URL:

https://nominatim.openstreetmap.org/search.php?q=Eiffel+tower%2C+Paris&format=json

If we drop the last parameter—format—the response will be a valid HTML page, showing the search results. This might be useful for debugging purposes.

Now, let's write some Python code to work with this API!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.8.216