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

Introducing Mapbox Android Services

$
0
0

Today we’re releasing Mapbox Android Services (MAS) v1.0, a new Java library to help consume Mapbox APIs on Android. Mapbox Android Services is the evolution of the existing geocoding and directions libraries, rearchitected to enable more features and faster iterations.

Getting started

We’ve ported all previously available functionality, including access to the latest directions and geocoding, and the autocomplete widget. All services are now contained within one package that you can add using Gradle:

dependencies {
    compile ('com.mapbox.mapboxsdk:mapbox-android-services:1.0.0@aar'){
        transitive=true
    }
}

Static API

Performance is paramount in mobile and, sometimes, to make your apps respond faster you don’t need to load a full map. For example, if you need to put multiple map thumbnails on a page showing who is dialing into the call, or a visual list of geotagged receipts, this is a quick and memory-efficient solution.

Use Mapbox Android Services to build the URL from the Mapbox Static API and use, for example, a RecyclerView to build a gallery of maps:

MapboxStaticImage staticImage = new MapboxStaticImage.Builder()
    .setAccessToken("...")
    .setStyleId(Constants.MAPBOX_STYLE_SATELLITE)
    .setLon(lon).setLat(lat)
    .setZoom(15).setBearing(45).setPitch(60)
    .setWidth(500).setHeight(500)
    .setRetina(true)
    .build();

Static Images is the first new API to be supported by Mapbox Android Services. We plan to include more in the future, let us know which one you want to see next.

RxJava support

Under the hood, we’re using the new Retrofit2 to build the interface to our services. This brings a good number of improvements, one that we’re particularly excited about: RxJava.

Once you’ve built your API client, you can call getObservable() to get the RxJava observable. And if you’re using RxAndroid, you could use the AndroidSchedulers object to create an asynchronous request that goes back to the main UI thread:

mapboxDirectionsclient.getObservable()
   .subscribeOn(Schedulers.newThread())
   .observeOn(AndroidSchedulers.mainThread())
   .subscribe(new Action1<DirectionsResponse>() {
      @Override
      public void call(DirectionsResponse response) {
         // Access the route information here
         DirectionsRoute currentRoute = response.getRoutes().get(0);
         Log.d(LOG_TAG, "Distance: " + currentRoute.getDistance());
   }
});

Pure Java

At the core of Mapbox Android Services we’ve built a Java-only package that you can use in your Java code, with no Android dependencies. This is well suited for backend services and command line tools.

You can also use Maven Central and Gradle to consume this library:

dependencies {
    compile ('com.mapbox.mapboxsdk:mapbox-java-services:1.0.0@jar'){
        transitive=true
    }
}

It supports all the APIs in Mapbox Android Services, including RxJava subscriptions and handling GeoJSON objects.

Use it today

Mapbox Android Services is available now. To start using it in your Java or Android project, check out the sample code and the installation page.

We’re continuing to work on in-app navigation support, make sure to sign up for updates.


Viewing all articles
Browse latest Browse all 2230

Trending Articles