Quantcast
Channel: maps for developers - Medium
Viewing all articles
Browse latest Browse all 2230

4 major features for the new Android SDK

$
0
0

Our new Android SDK launches today, baking in support for offline maps, intelligent telemetry, better map interactions, and improved compatibility with the Google Maps Android API.

Offline maps

Your app can now download arbitrary regions of the globe for offline use. For example, to download the current map view, to the maximum available zoom level, do the following:

// 1. Set up the OfflineManager
OfflineManager offlineManager = OfflineManager.getInstance(this);
offlineManager.setAccessToken("...");

// 2. Define the region
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
        mapboxMap.getStyleUrl(),
        mapboxMap.getProjection().getVisibleRegion().latLngBounds,
        mapboxMap.getCameraPosition().zoom,
        mapboxMap.getUiSettings().getMaxZoom(),
        this.getResources().getDisplayMetrics().density);

// 3. Set the metadata
byte[] metadata = ...; // This can be anything you want, for example, a JSONObject

// 4. Create the region asynchronously
offlineManager.createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback() {
    @Override
    public void onCreate(OfflineRegion offlineRegion) {
        // 5. And trigger the download (asynchronously, too)
        offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
    }
});

We take care of the rest: the SDK will automatically download the tiles and use them when available; later, it checks for updated tiles and automatically refreshes the offline map.

Telemetry

The world is a constantly changing place, and telemetry allows the map to keep up with it. Mapbox uses this anonymous data to add new roads, identify turn restrictions, and prioritize which places need new satellite imagery— all so that your app’s users have the most up-to-date maps as possible.

We’ve designed telemetry to be entirely anonymous, extremely lightweight, and efficient — it’s transparent to your app and your users. Setup consists of adding a one-line declaration to the app manifest.

<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/>

Camera API

The previous Camera API exposed only one method to change the camera position. With this release, we have added up to 12 new ways to manipulate its position. This includes updating with a certain zoom level, centering a camera position to a specific LatLngBounds or moving the camera to a certain position.

Dynamic markers

You can now update the position and the icon of a marker dynamically without having to fall back to removing and re-adding it. To do this, you can use marker.setPosition(LatLng position) and marker.setIcon(Icon icon).

dynamic-arker

Map padding

By default, a MapboxMap fills the entire region defined by its container element. With map padding, you can add a frame-like padding around the map to help you design UIs that can overlap the map, for example, to add places information, or to filter the data showed in a map.

map-padding

Improved API compatibility

With this release, we’ve made it much easier to help you migrate from the Google Maps Android API. For example, we have now decoupled the MapView and the MapboxMap objects, and it works exactly as you would expect:

// Set up the map view
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken("...");
mapView.setStyle(Style.MAPBOX_STREETS);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
    @Override
    public void onMapReady(@NonNull MapboxMap mapboxMap) {
        // The mapboxMap is ready.
        // You can now add markers, polylines and others
    }
});

You can now port your apps from Google Maps with less code. Your activities and fragments are easier to test, and more responsive thanks to the asynchronous nature of the MapboxMap.

Available now

To start building your app today with the new version 4.0.0 SDK, check out our documentation and installation instructions.


Viewing all articles
Browse latest Browse all 2230

Trending Articles