The Mapbox Java SDK is an open source toolset for building applications that need navigation, directions, geocoding, static map imagery, etc. It conveniently wraps Mapbox APIs and builds off of them with tools which are useful for your applications. This SDK has no dependency on the Android API and can be used in any of your Java projects.
- If you are looking for support using this SDK, either reach out through Stack Overflow or through our contact page.
- If you have found a bug, and can provide steps to reliably reproduce it, open an issue in the /mapbox-java repository on GitHub and apply the bug label.
- If you have a feature request, open an issue in the /mapbox-java repository on GitHub, and apply the enhancement label.
- If you want to contribute, look over our contribution guidelines and open a pull request with your changes.
All public methods in all the project modules are well documented and even include a since tag so you can find when an API was first added. You can find a link for all the module javadoc pages below:
Version above 3.0.0:
Version below 3.0.0:
If you plan to use any of our APIs such as directions, geocoding, navigation, etc. you'll need to have a Mapbox access token which you'll pass in as a parameter. An access token isn't needed if you plan to use the Mapbox Java SDK only for GeoJSON parsing or Turf calculations. Learn more about how access tokens work.
Throughout the APIs exposed within the Java SDK, you'll notice the common usage of the
Point object to represent a coordinate. The order in which the coordinate pair are longitude followed by latitude. Creating a new
Point is fairly straightforward and can be converted from a
LatLng object if you are using the Mapbox Maps SDK for Android.
The Java SDK will try to detect if your coordinates are outside the accepted range. This range is between -180 to 180 for longitudes and -90 to 90 for latitude. If the coordinates are outside the accepted range, the SDK will log a warning.
Note: if you happen to be using our Maps SDK with the Java SDK, you'll notice that the
LatLngobject has the reverse order; latitude comes before the longitude value.
Point point = Point.fromLngLat(LONGITUDE, LATITUDE);
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
Note: 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.
If your project's using Maven instead of Gradle, you can add the dependency inside your projects
<dependency> <groupId>com.mapbox.mapboxsdk</groupId> <artifactId>mapbox-sdk-services</artifactId> <version>4.6.0</version> </dependency>
In versions of the Mapbox Java SDK before 2.0, you would have to compile the entire package of APIs. This in some cases, could cause Android applications to go over the 65,536 method count limit.
Starting with 2.0, you now have the option to include either the entire package of APIs (using the dependencies listed above) or you can now selectively choose which specific APIs your application needs. For example, if you only need to handle GeoJSON serialization or deserialization inside your application you only need to include the GeoJSON dependency in your project.
The list below shows all the current separated dependencies you can use in your Android application.
If you're using a version above 3.0.0:
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-core:4.6.0' implementation 'com.mapbox.mapboxsdk:mapbox-sdk-geojson:4.6.0' implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:4.6.0' implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.6.0'
If you're using a version below 3.0.0:
implementation 'com.mapbox.mapboxsdk:mapbox-java-core:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-java-geojson:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-java-services:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-java-services-rx:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-android-services:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:VERSION_NUMBER' implementation 'com.mapbox.mapboxsdk:mapbox-android-ui:VERSION_NUMBER'
Note: ProGuard directives are included in the Android dependencies to preserve the required classes.