jungle-gif

50,000 maploads free every month. Get started now!

Flightmap SDK for Android

Flightmap SDK leverages the power of opensource MBGL sdk to render our custom map dataset.Our SDK supports current version : v1.0.3.6 and the following features:

  • Map styles

  • Camera manipulation

  • Gestures

Install the Flightmap SDK

Before starting to develop your application with the Flightmap SDK, you'll need to add the SDK as a dependency. You can find the following dependency given below in the MavenCentral repository. If your application is close or exceeds the 65k method count limit, you can mitigate this problem by enabling ProGuard inside your application. ProGuard directives are included in the Android dependencies to preserve the required classes. You can also shrink the file APK file size by making use of APK splitting.

Add the dependency
  • Start Android Studio

  • Android Project should be in Android X

  • Android Studio 3.+

  • Open up your application's build.gradle file.

  • Make sure that your project's minSdkVersion is at API 14 or higher.

  • Under dependencies, add a new implementation dependency line for the latest flightmap-android-sdk.

  • Find the File in the toolbar and then click on Sync Project with Gradle Files.

Note:Add the following dependency to your app module’s build.gradle file project/app/build.gradle:

dependencies {
implementation 'com.flightmap.flightmapsdk:flightmap:1.0.3.6'
}

Note:Add Maven in project build.gradle file in all project repository

allprojects {
repositories {
google()
jcenter()

maven { url 'https://dl.bintray.com/flightmap/com.flightmap' }

}
}

Additionally, running gradle app_module_name_here:dependencies in your command line will print a list of dependencies. ./gradlew app:dependencies works if you have a Gradle wrapper. They are helpful for troubleshooting nimble Gradle configurations when various libraries are included in a single project. You can see the dependencies that specific libraries are bringing and where conflicts might be happening.

Get an access token

Copy your default public token to your clipboard. After you've added the Maps SDK as a dependency inside of your Android project, open the R.strings.xml file, create a new String resource, and paste the access token.

FLIGHTMAP_ACCESS_TOKEN

Then to pass this into the Flightmap SDK, you'll want to place the access token inside of your application's onCreate() method.

public class MyApplication extends Application {

@Override public void onCreate() {
super.onCreate()

// Flightmap Access token
Mapbox.getInstance(getApplicationContext(), getString(R.string.flightmap_access_token))
}
}

The Flightmap SDK also provides a setToken() method in case you want to switch the Flightmap access token at runtime.

Mapbox.setAccessToken(FLIGHTMAP_ACCESS_TOKEN);

Setup permissions

Starting with the 5.0 version of the Maps SDK, you can use the Manifest merge feature to reduce the need to include any Maps SDK required things inside of your application's manifest file. You'll need to add either the Fine or Coarse location permission if you plan to display a user's location on the map or get the user's location information. The user location permission should also be checked during runtime using the PermissionsManager.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>

Add a map

Open the Java file of the activity where you'd like to include the map in and add the code below to the file.

private MapView mapView;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)

Mapbox.getInstance(this, getString(R.string.flightmap_access_token*

setContentView(R.layout.activity_main)
mapView = (MapView) findViewById(R.id.mapView)
mapView.onCreate(savedInstanceState(
mapView.getMapAsync(new OnMapReadyCallback() {
@Override public void onMapReady(@NonNull MapboxMap mapboxMap) {
mapboxMap.setStyle(Style.DARK, new Style.OnStyleLoaded() {
@Override
public void onStyleLoaded@(NonNull Style style) {
// Map is set up and the style has loaded. Now you can add data or make other map adjustments
}
})
}
})
}

To set style with URL.
  • Dark Theme:https://maps.flightmap.io/styles/style-dark.json

  • LightTheme:https://maps.flightmap.io/styles/style-bright.json

mapboxMap.setStyle(new Style.Builder().fromUri("https://maps.flightmap.io/styles/style-dark.json"),
new Style.OnStyleLoaded() {
@Override public void onStyleLoaded(@NonNull Style style) {
}
})

Open the activity's XML layout file and add the mapView within your layout.

<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

Lifecycle methods

The MapView contains its own lifecycle methods for managing Android's OpenGL lifecycle, which must be called directly from the containing Activity. In order for your app to correctly call the MapView's lifecycle methods, you must override the following lifecycle methods in the Activity that contains the MapView and call the respective MapView method. For example, your onStart() method should look like this:

@Override
protected void onStart() {
super.onStart()
mapView.onStart()
}

Like the onStart() override above, the following lifecycle methods also need to be overridden and include the matching MapView method:

@Override
protected void onResume() {
super.onResume()
mapView.onResume()
}

@Override
protected void onPause() {
super.onPause()
mapView.onPause()
}

@Override
protected void onStop() {
super.onStop()
mapView.onStop()
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState) mapView.onSaveInstanceState(outState) }

@Override
public void onLowMemory() {
super.onLowMemory()
mapView.onLowMemory()
}

@Override
protected void onDestroy() {
super.onDestroy()
mapView.onDestroy()
}

If you're using a fragment, call mapview.onDestroy() inside the fragment's onDestroyView() method rather than inside onDestroy():

@Override
public void onDestroyView() {
super.onDestroyView()
mapView?.onDestroy()
}

Add Marker

Markers are useful when identifying a single point on the map. The SDK comes with a default marker icon which can be configured to fit your specific needs. APIs are exposed to optionally change this icon to any bitmap image you wish. To create a marker for you map, you are only required to provide a LatLng position which defines where the marker will be placed on the map. Call mapboxMap.addMarker() to add the marker to the map.

mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(48.85819, 2.29458))
.title("Eiffel Tower"))

Add a list of markers using mapboxMap.addMarkers() if you have many markers or are loading them from a GeoJSON file.

Removing markers

The Flightmsp Android SDK comes with two methods for removing markers. If you'd like to remove a particular marker, use mapboxMap.removeMarker() while passing in the marker object to be removed. If you would like to remove all markers, call the mapboxMap.clear() method. Note that this will also remove any polylines and polygons you’ve added to your map.

Customize marker icon

You can specify a custom icon by using the IconFactory object and passing it to the marker. The default marker icon's used if you don’t specify an icon while creating your marker. The anchoring of the marker will be in the center, meaning if you have an icon with a point, you'll need to add padding to the bottom of the image.

IconFactory iconFactory = IconFactory.getInstance(MainActivity.this)
Icon icon = iconFactory.fromResource(R.drawable.blue_marker)
mapboxMap.addMarker(new MarkerOptions()
.position(new LatLng(48.85819, 2.29458))
.icon(icon))

Add polyline

Adding a line or polygon to your map is like adding a marker. Due to the nature of these objects, different APIs are exposed, such as polygon color or line width. Instead of taking in a single position, bundle all your LatLng objects inside of a List and then pass them in using the addAll() method.

mapboxMap.addPolyline(new PolylineOptions()
.addAll(points)
.color(Color.parseColor("#3bb2d0"))
.width(2))

Let's find a way together

Get in touch to know about our Pricing Plans

Contact Us