Blog of Sara Jakša

Get Nearby Places with Open Street Maps and Overpass API

Well, one of the things, that I will have to implement in my app in the near future was the suggestion for nearby places. The person showing my this recommended Foursquare API, but I decided to first try something a bit more open source.

Open Street Map has some great maps, so this was my first try. Would it be possible to get what I wanted with it? They ask not to get too much data in a day. My test query produced a little less than 5KB, so I hope that would not be much. In case we ever get a lot of users, I am sure, we could host a subset of the data on our own servers.

I have to admit, it took me a lot more time to find out what API to use, and to try and research the difference between QL and XML and why there are two languages and how can each be used, that actually trying to understand how to make queries.

This is quite different from school work. They well you, where the data is and it one form, and then they make you master querying. Or maybe they had a good enough effect.

Well, before I tried to implement it inside of react-native, I tried it in a python code. The below code queries the places near faculty rooms for my study program. They only list the names entries, so they might be some missing. One can chance the latitude, longitude and range easily.

from bs4 import BeautifulSoup
import requests

lat = 46.04908
lon = 14.50468
rad = 50

data = requests.get("http://overpass-api.de/api/interpreter?data=<query type='node'><around lat='" + 
                    str(lat) + 
                    "' lon='" + 
                    str(lon) + 
                    "' radius='" + 
                    str(rad) + 
                    "'/></query><print/>")

data = data.text
data=BeautifulSoup(data, features="xml")
all_nearby_locations = data.find_all("tag", {"k":"name"})
[loc["v"] for loc in all_nearby_locations]

I don't know, bit for now, it seems like a relatively good solution. Now to figure out, how I am going to get these names out of the XML in react-native (hopefully without additional libraries - I have the feeling I use too many of them already).