osmapi-overpass is a client for the Overpass API, building on top of osmapi.
© 2019-2023 Tobias Zwick. This library is released under the terms of the GNU Lesser General Public License (LGPL).
Add de.westnordost:osmapi-overpass:3.0
as a Maven dependency or download the jar from there.
On Android, you need to exclude kxml2 from the dependencies in your gradle.kts
since it is already built-in, like so:
configurations {
all {
// it's already included in Android
exclude(group = "net.sf.kxml", module = "kxml2")
exclude(group = "xmlpull", module = "xmlpull")
}
}
This library uses classes from the Java 8 time API, like Instant
etc., so if your app supports Android API levels below 26, you need to enable Java 8+ API desugaring support.
First, initialize the OverpassMapDataApi
OsmConnection connection = new OsmConnection("https://overpass-api.de/api/", "my user agent");
OverpassMapDataApi overpass = new OverpassMapDataApi(connection);
then...
overpass.queryElements(
"[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out meta;",
handler
);
overpass.queryElementsWithGeometry(
"[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out meta geom;",
handler
);
overpass.queryTable(
"[out:csv(name, shop)][bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out body;",
handler
);
ElementCount count = overpass.queryCount(
"[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out count;"
);
The query string is just passed through to the Overpass API. For how the query string needs to look like, consult the documentation for Overpass API Query Language.