map

Uploads all artifacts belonging to configuration ':libs:map:archives'

License

License

GroupId

GroupId

de.westnordost
ArtifactId

ArtifactId

osmapi-map
Last Version

Last Version

2.0
Release Date

Release Date

Type

Type

jar
Description

Description

map
Uploads all artifacts belonging to configuration ':libs:map:archives'
Project URL

Project URL

https://github.com/westnordost/osmapi
Source Code Management

Source Code Management

https://github.com/westnordost/osmapi

Download osmapi-map

How to add to project

<!-- https://jarcasting.com/artifacts/de.westnordost/osmapi-map/ -->
<dependency>
    <groupId>de.westnordost</groupId>
    <artifactId>osmapi-map</artifactId>
    <version>2.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.westnordost/osmapi-map/
implementation 'de.westnordost:osmapi-map:2.0'
// https://jarcasting.com/artifacts/de.westnordost/osmapi-map/
implementation ("de.westnordost:osmapi-map:2.0")
'de.westnordost:osmapi-map:jar:2.0'
<dependency org="de.westnordost" name="osmapi-map" rev="2.0">
  <artifact name="osmapi-map" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.westnordost', module='osmapi-map', version='2.0')
)
libraryDependencies += "de.westnordost" % "osmapi-map" % "2.0"
[de.westnordost/osmapi-map "2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
de.westnordost : osmapi-core jar 2.0

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
de.westnordost » testutils jar unspecified
de.westnordost : osmapi-changesets jar 2.0

Project Modules

There are no modules declared in this project.

osmapi

osmapi is a client for the OSM API 0.6.

It is well tested (test coverage over 90%) and being used by StreetComplete, thus actively maintained.

Note, the OSM API, particularly the part to download the map data, is intended only for editing the map. It's not made for pulling larger amounts of data or data analysis of certain map features. If this is what you intend to do, the Overpass API is what you will want to use. I created a basic Java client for the Overpass API here, it builts upon this library: osmapi-overpass.

Copyright and License

© 2016-2021 Tobias Zwick. This library is released under the terms of the GNU Lesser General Public License (LGPL).

Installation

Depending on which part of the API you use, you can only include what you need:

Class Dependency Description
CapabilitiesApi
de.westnordost:osmapi-core:2.0
Getting server capabilities
PermissionsApi
de.westnordost:osmapi-core:2.0
Getting user permissions
MapDataApi
de.westnordost:osmapi-map:2.0
Getting map data, querying single elements and their relations toward each other and uploading changes in changesets
MapDataHistoryApi
de.westnordost:osmapi-map:2.0
Getting the history and specific versions of elements
NotesApi
de.westnordost:osmapi-notes:2.0
Getting finding, creating, commenting on and solving notes
GpsTracesApi
de.westnordost:osmapi-traces:2.0
Getting, uploading, updating and deleting GPS traces and trackpoints
ChangesetsApi
de.westnordost:osmapi-changesets:2.0
Finding changesets, changeset discussion, subscription and data
UserApi
de.westnordost:osmapi-user:2.0
Getting user information
UserPreferencesApi
de.westnordost:osmapi-user:2.0
Managing user preferences

To include everything, add de.westnordost:osmapi:4.0 as a Maven dependency or download the jar from there.

Android

On Android, you need to exclude kxml2 from the dependencies since it is already built-in, like so:

dependencies {
    implementation 'de.westnordost:osmapi:4.0'
}

configurations {
    // already included in Android
    all*.exclude group: 'net.sf.kxml', module: 'kxml2'
    
    // @NonNull etc annotations are also already included in Android
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains', module:'annotations'
    compile.exclude group: 'com.intellij', module:'annotations'
    compile.exclude group: 'org.intellij', module:'annotations'
}

Also, starting with v4.0 (or v2.0 of the modularized version respectively), this library uses the classes from the Java 8 time API, like Instant etc. instead of Date which leads to about 50% faster parsing times when receiving a result.

If your app supports Android API levels below 26, you have two options:

  1. Either stick to using version 3.x (or v1.x of the modularized version respectively) of this library...
  2. ...or enable Java 8+ API desugaring support for your app

Basic Usage

Everything revolves around the OsmConnection, this is the class that talks to the Api. Specify where to reach the Api, how the client should identify itself towards the server etc. If you plan to make calls that can only be made by a logged in user, such as uploading map data, an OAuthConsumer (third parameter) needs to be specified.

    OsmConnection osm = new OsmConnection(
        "https://api.openstreetmap.org/api/0.6/",
        "my user agent", null
    );

You can call osm.makeRequest(...) yourself to talk with the RESTful Api and write your own ApiRequestWriter and ApiResponseReader to write/read the request. It is more convenient however to use the appropriate class to do that for you and return the data you are interested in. See the table above for which classes are available.

For example...

Create a note

    Note myNote = new NotesApi(osm).create(position, "My first note");

Comment a changeset

    ChangesetInfo changeset = new ChangesetsApi(osm).comment(id, "Nice work!");

Get user info

    UserInfo user = new UserApi(osm).get(id);

Download map data

    MapDataApi mapApi = new MapDataApi(osm);
    mapApi.getMap(boundingBox, myMapDataHandler);

myMapDataHandler implements MapDataHandler whose methods are called as the elements are parsed, think SAX parser. I.e. if you download 10MB of data, then the elements start arriving at the handler as the data comes in so that you can process them on the fly.

    /** This class is fed the map data. */
    public interface MapDataHandler
    {
        void handle(Bounds bounds);

        void handle(Node node);
        void handle(Way way);
        void handle(Relation relation);
    }

Combine with data processing library

Read this if you want to use this library in conjunction with a data processing library like Osmosis, osm4j or have your own map data structures already.

Troubleshooting

If you are getting the exception

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

, try updating your Java SDK. Openstreetmap.org uses Let's Encrypt certificates which are not trusted in earlier versions of Java by default. Read more here.

Versions

Version
2.0
1.5
1.4
1.3
1.2
1.1
1.0