The Mapbox Java SDK is an open source toolset for building applications that need directions, geocoding, static map images, geospatial calculations, and more. It conveniently wraps Mapbox APIs for use in any Java application. This SDK has no dependency on the Android API and can be used in any Java-only project.
Here are the current Java SDK dependencies that you can use in your Android or other Java project.
GeoJSON: Java classes that model the GeoJSON spec.
Services: Convenient wrappers to interact with Mapbox APIs: Matrix, Geocoding, Tilequery, Optimization, Static Image, Map Matching, and Isochrone.
Turf: Runtime geospatial calculations.
Core: Color, text, and networking utility classes.
To start developing your application using the Mapbox Java SDK, you'll need to first decide which installation method works for you. The SDK is fully compatible with Android using Gradle and can also be included in a generic Java project using either Gradle or Maven. You can find all dependencies given below on MavenCentral.
- Start Android Studio.
- Open up your application's app-level
- Make sure that your project's
minSdkVersionis set to API 14 or higher.
- In the dependencies block, add a new
implementationdependency for the Java SDK package(s) you want in your project.
Sync Project with Gradle Filesnear the toolbar in Android Studio.
If your project is close or exceeds the 65k method count limit, you can mitigate this problem by specifying only the specific Mapbox Android Service APIs. See the selectively compiling APIs section below.
// Replace `DESIRED_JAVA_SDK_PACKAGE` with the // name of one of the packages listed at the top of this page. implementation 'com.mapbox.mapboxsdk:DESIRED_JAVA_SDK_PACKAGE:5.2.1'
If your project is using Maven instead of Gradle, you can add the dependency inside your project's
<dependency> <groupId>com.mapbox.mapboxsdk</groupId> <!-- Replace `DESIRED_JAVA_SDK_PACKAGE` with the name of one of the packages listed in the next section--> <artifactId>DESIRED_JAVA_SDK_PACKAGE</artifactId> <version>5.2.1</version> </dependency>
You'll need to have a Mapbox access token if you plan to use any of the
mapbox-sdk-services Mapbox APIs wrappers. An access token is not needed if you plan to use the Mapbox Java SDK's GeoJSON package, Turf package, or certain parts of the Core package. Learn more about how Mapbox access tokens work.