With feature querying in the latest release of our iOS SDK, your iOS application can take any street, landmark, or business that’s on the map and display additional information about it anywhere on the screen. That way you don’t have to clutter up the map itself with these details. Feature querying gives you access to the raw geometry and metadata that the SDK uses to draw the map, whether it’s the OpenStreetMap-based Mapbox Streets source that powers the default base map or your own datasets that you manage in Mapbox Studio. Feature querying uses the data that the user has already downloaded in order to view the map, so it even works offline.
Now that you can connect OpenStreetMap and Wikidata, let’s see how you can use feature querying in your own application to take advantage of these two open data projects. I built a simple application for iPhone and iPad, shown below. When you press and hold on a bridge on the map, the bridge is highlighted and images of other works by the bridge’s designer pop up:
The SDK fetches Mapbox Vector Tiles, which contain raw data and associated metadata for each business, building, street, and pond. The SDK uses this data to draw the map, which is why you can easily switch styles or tilt the map without having to redownload any map tiles.
First, I obtain the bridge feature under the user’s finger via the -[MGLMapView visibleFeaturesAt:] method. The feature’s raw geometry allows me to draw a highlight over the road, using a shape annotation, but I could just as easily position a popover somewhere along the road or display the road’s name in the navigation bar. Thanks to the SDK’s offline maps feature, the application can extract the raw geometry and tags from the vector tiles even if the user puts the phone in Airplane Mode.
For this application, though, I want to get some additional metadata about the bridge that’s normally omitted from the vector tiles to reduce data usage. So I pass the feature’s unique identifier into OpenStreetMap’s Overpass API to get all the raw tags for that feature in JSON format, including the Wikipedia article and Wikidata item. Finally, I ask the Wikidata Query Service for freely licensed Wikimedia Commons images of other works by that bridge’s architect.
Wikidata opens the door to a wealth of free content, including this photo of the Roebling Suspension Bridge from Wikimedia Commons. (Adam Sofen, CC BY)
Notably, none of these steps involves fuzzy text searches, specialized geospatial software, or Wikipedia’s labyrinthine wikitext format. The entire process is based on definitive relationships and structured JSON data. What’s more, each tool I used is open source software: the Overpass API, the Wikidata Query Service, and the Mapbox iOS SDK. Likewise, the OpenStreetMap and Wikidata data sets are both freely licensed projects built largely by volunteer contributions.