Top Banner
Building Location-Aware Apps with Open Source & Open Data Chuck Greb | 9·21·2014 | Droidcon NYC
88

Building Location-Aware Apps with Open Source & Open Data

May 27, 2015

Download

Technology

Chuck Greb

A map can show you where you are or how to get from here to there. But in a world of location aware devices maps can do so much more. Maps and location-based features are the foundation for many apps and provide a rich contextual experience that transforms based on your environment. Open source location services and map frameworks can give you greater transparency, flexibility, compatibility, and control when building location-based apps. This talk will explore how to implement maps and other location-aware features on Android using open source and open data.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Chuck Greb | 9·21·2014 | Droidcon NYC

Page 2: Building Location-Aware Apps with Open Source & Open Data

start where you are

Page 3: Building Location-Aware Apps with Open Source & Open Data
Page 4: Building Location-Aware Apps with Open Source & Open Data
Page 5: Building Location-Aware Apps with Open Source & Open Data
Page 6: Building Location-Aware Apps with Open Source & Open Data
Page 7: Building Location-Aware Apps with Open Source & Open Data
Page 8: Building Location-Aware Apps with Open Source & Open Data
Page 10: Building Location-Aware Apps with Open Source & Open Data

start where you are

Page 11: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Page 12: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Page 13: Building Location-Aware Apps with Open Source & Open Data

3 kinds of location-aware apps

⇢ Map applications

⇢ Location based apps

⇢ Apps with location aware features

Location-Aware Apps

Page 14: Building Location-Aware Apps with Open Source & Open Data
Page 15: Building Location-Aware Apps with Open Source & Open Data
Page 16: Building Location-Aware Apps with Open Source & Open Data
Page 17: Building Location-Aware Apps with Open Source & Open Data
Page 18: Building Location-Aware Apps with Open Source & Open Data
Page 19: Building Location-Aware Apps with Open Source & Open Data
Page 20: Building Location-Aware Apps with Open Source & Open Data
Page 21: Building Location-Aware Apps with Open Source & Open Data
Page 22: Building Location-Aware Apps with Open Source & Open Data
Page 23: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Page 24: Building Location-Aware Apps with Open Source & Open Data

Philosophy

Open Source

Page 25: Building Location-Aware Apps with Open Source & Open Data

Code

Open Source

Page 26: Building Location-Aware Apps with Open Source & Open Data

License

Open Source

Page 27: Building Location-Aware Apps with Open Source & Open Data

Community

Open Source

Page 28: Building Location-Aware Apps with Open Source & Open Data

Advantages

⇢ Transparency

⇢ Flexibility

⇢ Compatibility

⇢ Free!

Open Source

Page 29: Building Location-Aware Apps with Open Source & Open Data

Open source is not free like beer

Open Source

Page 30: Building Location-Aware Apps with Open Source & Open Data

Open source is free like a puppy

Open Source

Page 31: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Page 32: Building Location-Aware Apps with Open Source & Open Data

Availability & Access

Open Data

Page 33: Building Location-Aware Apps with Open Source & Open Data

Reuse & Redistribution

Open Data

Page 34: Building Location-Aware Apps with Open Source & Open Data

Universal participation

Open Data

Page 35: Building Location-Aware Apps with Open Source & Open Data

Open Knowledge Foundationhttps://okfn.org/

Open Data

Page 36: Building Location-Aware Apps with Open Source & Open Data

Building Location-Aware Appswith Open Source & Open Data

Page 37: Building Location-Aware Apps with Open Source & Open Data

Components

Open Location Applications

Page 38: Building Location-Aware Apps with Open Source & Open Data

Datasource

Open Location Applications

Page 39: Building Location-Aware Apps with Open Source & Open Data

Vector Tiles

Open Location Applications

Page 40: Building Location-Aware Apps with Open Source & Open Data

Renderer

Open Location Applications

Page 41: Building Location-Aware Apps with Open Source & Open Data

Location Services

Open Location Applications

GPS, Network, Sensors, BLE

Page 42: Building Location-Aware Apps with Open Source & Open Data

Geocoder

Open Location Applications

Page 43: Building Location-Aware Apps with Open Source & Open Data

Search Engine

Open Location Applications

Page 44: Building Location-Aware Apps with Open Source & Open Data

Route Engine

Open Location Applications

Page 45: Building Location-Aware Apps with Open Source & Open Data

OpenStreetMap (OSM)

Page 46: Building Location-Aware Apps with Open Source & Open Data

⇢ Crowdsourced Data

⬝ Local knowledge

⬝ Community driven

⇢ Public Data

⬝ 2007 TIGER import

⬝ Manual import process

⇢ Open Data Commons Open Database License (ODbL)

⬝ Attribution

⬝ Share-Alike

⬝ Keep Open

OpenStreetMap (OSM)

Page 47: Building Location-Aware Apps with Open Source & Open Data
Page 48: Building Location-Aware Apps with Open Source & Open Data

osmdroid

Page 49: Building Location-Aware Apps with Open Source & Open Data

2008

osmdroid

Page 50: Building Location-Aware Apps with Open Source & Open Data

Based on Google Maps API v1

osmdroid

Page 51: Building Location-Aware Apps with Open Source & Open Data

Support for online and offline tile source

osmdroid

Page 52: Building Location-Aware Apps with Open Source & Open Data

Icons, tracking, and shapes

osmdroid

Page 53: Building Location-Aware Apps with Open Source & Open Data
Page 54: Building Location-Aware Apps with Open Source & Open Data

Mapbox

Page 55: Building Location-Aware Apps with Open Source & Open Data

Fork of osmdroid

Mapbox

Page 56: Building Location-Aware Apps with Open Source & Open Data

Easy integration with Mapbox tile server

Mapbox

Page 57: Building Location-Aware Apps with Open Source & Open Data

<com.mapbox.mapboxsdk.views.MapView

android:id="@+id/mapview"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

mapbox:mapid="Your Mapbox mapid" />

Mapbox

Page 58: Building Location-Aware Apps with Open Source & Open Data

MapView mapView = new MapView(this, "Your Mapbox mapid");

this.setContentView(mapView);

Mapbox

Page 59: Building Location-Aware Apps with Open Source & Open Data

(Alternate tile servers also supported)

Mapbox

Page 60: Building Location-Aware Apps with Open Source & Open Data

Custom styles & satellite imagery

Mapbox

Page 61: Building Location-Aware Apps with Open Source & Open Data
Page 62: Building Location-Aware Apps with Open Source & Open Data

OpenScienceMap

Page 63: Building Location-Aware Apps with Open Source & Open Data

Universität Bremen

OpenScienceMap

Page 64: Building Location-Aware Apps with Open Source & Open Data

“OpenScienceMap provides free and open maps for Android with the fastest and 100% pure vector maps around.”

OpenScienceMap

Page 65: Building Location-Aware Apps with Open Source & Open Data

<org.oscim.android.MapView

android:id="@+id/map"

android:layout_width="match_parent"

android:layout_height="match_parent" />

OpenScienceMap

Page 66: Building Location-Aware Apps with Open Source & Open Data

public class MyActivity extends MapActivity {

...

public Map getMap() {

return super.map();

}

}

OpenScienceMap

Page 67: Building Location-Aware Apps with Open Source & Open Data

@Override public void onCreate(Bundle icicle) {

super.onCreate(icicle);

UrlTileSource tileSource = new OSciMap4TileSource("http://vector.example.com/all");

VectorTileLayer baseLayer = getMap().setBaseMap(tileSource);

getMap().layers().add(new BuildingLayer(getMap(), baseLayer));

getMap().layers().add(new PoiLayer(getMap(), baseLayer));

getMap().layers().add(new LabelLayer(getMap(), baseLayer));

baseLayer.setRenderTheme(ThemeLoader.load(

AssetAdapter.g.openFileAsStream("styles/map.xml)")));

}

OpenScienceMap

Page 68: Building Location-Aware Apps with Open Source & Open Data
Page 69: Building Location-Aware Apps with Open Source & Open Data

Mapzen

Page 70: Building Location-Aware Apps with Open Source & Open Data

Pelias

Mapzen

Page 71: Building Location-Aware Apps with Open Source & Open Data

getPelias().suggest("Empire State Build", Callback<Result>);

getPelias().search("Empire State Building", "x1,y1,x2,y2", Callback<Result>);

Mapzen (Pelias)

Page 72: Building Location-Aware Apps with Open Source & Open Data

On the Road

Mapzen

OSRM

Page 73: Building Location-Aware Apps with Open Source & Open Data

Router.getRouter().setEndpoint("http://osrm.example.com")

.setDriving()

.setLocation(new double[]{lat, lng})

.setLocation(new double[]{lat, lng})

.setCallback(new Callback() {

@Override

public void success(Route route) {

// do stuff

}

@Override

public void failure(int statusCode) {

// do stuff

}

}).fetch();

Mapzen (On the Road)

Page 74: Building Location-Aware Apps with Open Source & Open Data

LOSTLocation Open Source TrackerLocation Open Source Tracker

Mapzen

Page 75: Building Location-Aware Apps with Open Source & Open Data

LocationClient locationClient = new LocationClient(context,

new LocationClient.ConnectionCallbacks() {

@Override public void onConnected(Bundle bundle) {

onLocationClientConnected();

}

@Override public void onDisconnected() {

onLocationClientDisconnected();

}

});

Mapzen (LOST)

Page 76: Building Location-Aware Apps with Open Source & Open Data

private void onLocationClientConnected() {

Location lastLocation = locationClient.getLastLocation();

if (lastLocation != null) {

// do stuff

}

LocationRequest locationRequest = LocationRequest.create();

locationRequest.setInterval(5000);

locationClient.requestLocationUpdates(locationRequest,

new LocationListener() {

@Override public void onLocationChanged(Location location) {

// do more stuff

}

});

}

Mapzen (LOST)

Page 77: Building Location-Aware Apps with Open Source & Open Data

Mapzen Android Demo

Mapzen

Page 78: Building Location-Aware Apps with Open Source & Open Data

Mapzen Android Demo

Pelias Android SDK On the Road LOSTOpenScienceMap

VTM Speakerbox

TTSLocationManagerOSRMPeliasVector

Datasource OpenGL ES

Page 79: Building Location-Aware Apps with Open Source & Open Data
Page 80: Building Location-Aware Apps with Open Source & Open Data
Page 81: Building Location-Aware Apps with Open Source & Open Data
Page 82: Building Location-Aware Apps with Open Source & Open Data
Page 83: Building Location-Aware Apps with Open Source & Open Data
Page 84: Building Location-Aware Apps with Open Source & Open Data

start where you are

Page 85: Building Location-Aware Apps with Open Source & Open Data
Page 86: Building Location-Aware Apps with Open Source & Open Data
Page 87: Building Location-Aware Apps with Open Source & Open Data
Page 88: Building Location-Aware Apps with Open Source & Open Data

Ineke!Chuck Greb | @ecgreb

github.com/mapzen