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.
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 most of the project (besides the Android dependent modules) 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 applications
- Make sure your projects
minSdkVersionis at API 14 or higher
- Under dependencies add a new build rule for the latest mapbox-android-services
- Click the Sync Project with Gradle Files near the toolbar in Studio
If your application 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 in the next section */ implementation 'com.mapbox.mapboxsdk:DESIRED_JAVA_SDK_PACKAGE:5.0.0'
If your project's using Maven instead of Gradle, you can add the dependency inside your projects
<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.0.0</version> </dependency>
Here are the current Java SDK dependencies, which you can use in your Android/Java project.
GeoJSON – Java classes which model the GeoJSON spec.
Services – Convenient wrappers to interact with Mapbox APIs: Matrix, Geocoder, Tilequery, Optimization, Static Image, Map Matching, and Isochrone.
Turf for Java - Runtime on-device geospatial calculations.
Core - Color, text, and networking utility classes.
You'll need to have a Mapbox access token if you plan to use any of the
mapbox-sdk-services wrappers around Mapbox APIs. An access token is not needed if you plan to use the Mapbox Java SDK's GeoJSON library, Turf library, or certain parts of its Core library. Learn more about how access tokens work.
The Java SDK uses the
Point object to represent a geographical coordinate.
Point objects contain two values, longitude and latitude, in that order. This order is the reverse of the
LatLng object in the Mapbox Maps SDK for Android. If you are using the Maps SDK and the Java SDK together, you will need to convert between
Point point = Point.fromLngLat(LONGITUDE, LATITUDE);