Search code examples
javaandroidoverpass-api

Overpasser library using


Ok, I'm trying to use overpasser library https://github.com/zsoltk/overpasser, and for some reason when I'm trying to use default example from github page it return nothing as OverpassQueryResult, tried putting different data, and google a lot - no usefull info. thanks in advance for any help

OverpassQueryResult overpassQueryResult = search(new LatLngBounds(new LatLng(180, -180), new LatLng(180,-180)));


        if(overpassQueryResult.elements!=null) {
            Log.d(TAG, "overpassQueryResult size " + overpassQueryResult.elements.size());
        } else {
            Log.d(TAG, "overpassQueryResult is null ");
        }

public OverpassQueryResult search(final LatLngBounds bounds) {
    OverpassQuery query = new OverpassQuery()
            .format(JSON)
            .timeout(30)
            .filterQuery()
            .node()
            .amenity("cafe")
            .tagNot("access", "private")
            .boundingBox(
                    bounds.southwest.latitude,
                    bounds.southwest.longitude,
                    bounds.northeast.latitude,
                    bounds.northeast.longitude
            )
            .end()
            .output(100)
            ;
    Log.d(TAG, query.build());
    return interpret(query.build());
}



private OverpassQueryResult interpret(String query) {
        try {
            return OverpassServiceProvider.get().interpreter(query).execute().body();

        } catch (Exception e) {
            e.printStackTrace();

            return new OverpassQueryResult();
        }
    }

Solution

  • This library is no longer maintained since 4 years and creates invalid Overpass QL queries. The reason for the error is that Overpass API backend simply rejects the broken query.

    I described this in more detail here: https://github.com/zsoltk/overpasser/issues/19

    Maybe you're able to fix the code, or even better use some other library which is still maintained.