OpenStreetMap rendering on Android
Computer Science Institute Freie Universitt Berlin
Agenda
Quick introduction of the mapsforge project OpenStreetMap on Android
Our approach to mobile map rendering Our free map library for Android Our free map application for Android Hello, MapView
Routing with OpenStreetMap data Questions and live demo
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
About mapsforge
The mapsforge project
initiated at the computer science institute of Freie Universitt Berlin was started in 2008 provides free mapping and navigation tools is based on OpenStreetMap and free software currently involves 10 students and scientific staff since April 2010 at Google Project Hosting uses the GPL3 license for all source code
http://mapsforge.org
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
What we do
Creating various tools for
Map rendering and overlays Route planning POI indexing and search Spatial data formats and algorithms
Focus is on mobile devices
Currently only Android In the future also other platforms
We aim for maximum flexibility
Configurable map extraction and rendering Configurable navigation and routing Online and offline services
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
OpenStreetMap on Android
The OpenStreetMap (OSM) project
Creative Commons license Map data can be downloaded as XML files Rendered tiles available as PNG files
Many applications for OSM on Android exist
Not all of them are free software Only few can work completely offline Only very few render map images on the device
Advantages of rendering OpenStreetMap offline
No internet connection required Saving money and privacy Much more flexible than static tiles
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
Our approach to mobile map rendering
All map data is stored on the device
Preprocessing of OSM data with a converter
Input: Raw OSM map data (Berlin: ~170 MB) Output: Single binary file (Berlin: 15 MB, full details including names) No pre-rendering of images or tiles Finally the map file is copied to SD card
Tile based rendering
Tile = small, rectangular part of a map De facto standard for online maps Advantages
Incremental map rendering better user experience Allows caching higher frame rate
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
Challenges of mobile map rendering
Rendering a map tile is difficult
Get all map data that intersects it Correct handling of overlapping map objects Fast but accurate map projection Filter map objects by zoom level Collision free label placement Scheduling of all required tiles
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
Android specific challenges
Memory Management
Only 16 MB of RAM per process (or 24 MB, depending on the device) Return value of Runtime.freeMemory() not reliable Be aware of memory leaks
Issues with Android activity lifecycle
No single exit point (application maybe killed by OS) Delayed execution of onStop() and onDestroy() potential race conditions potential OutOfMemoryException Handling of configuration change (e.g. orientation, language)
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
Android specific challenges (continued)
Performance tuning for Dalvik VM
Know your development platform Designing for Performance A JIT Compiler for Android's Dalvik VM (since version 2.2)
Avoid garbage collection
Consider object pools Class variables instead of local variables
Multiple Android versions and devices
Be aware of market fragmentation (regarding different versions) Different screen resolutions and densities Device-specific bugs :-(
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
Our free map library for Android
Library for rendering map tiles on different zoom levels
Implements important classes and methods from the Google Maps for Android API High level of detail and rendering quality
Subset of ~170 OpenStreetMap tags Each tag can be rendered individually with name and symbol
Intelligent caching of tiles in RAM and on SD card Integrated map scale and zoom controls
Key class is the MapView
Handles user input via touchscreen, keys or trackball Assembles tiles into one big image on the screen Achieves 30-40 FPS (depending on cache hits)
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
10
Architectural View of Map Rendering
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
11
Our free map application for Android
Working title: AdvancedMapViewer
Runs on all Android versions 1.5 Uses our map library and MapView Serves as demo application and test case
Some features
Select map file in a file browser Configuration via preferences Follow current GPS position Enter new coordinates Currently included languages: English, German, Finnish
You can download the APK file and several
preprocessed map files at our website
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
12
Hello, MapView (Google Version)
import android.os.Bundle; import com.google.android.maps.MapActivity; import com.google.android.maps.MapView; public class HelloMapView extends MapActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapView mapView = new MapView(this, "Your Maps API Key"); mapView.setClickable(true); mapView.setBuiltInZoomControls(true); setContentView(mapView); } @Override protected boolean isRouteDisplayed() { return false; }
AndroidManifest.xml: <uses-permission android:name="android.permission.INTERNET" />
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
13
Hello, MapView (mapsforge Version)
import android.os.Bundle; import com.google.android.maps.MapActivity org.mapsforge.android.map.MapActivity; import com.google.android.maps.MapView org.mapsforge.android.map.MapView; public class HelloMapView extends MapActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapView mapView = new MapView(this, "Your Maps API Key"); mapView.setClickable(true); mapView.setBuiltInZoomControls(true); mapView.setMapFile("/sdcard/berlin.map"); setContentView(mapView); } @Override protected boolean isRouteDisplayed() { return false; }
New!
AndroidManifest.xml: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
14
What comes next
Map rendering module
Fix known issues Improve Overlay API Use OpenGL for map rendering
Hardware acceleration Better drawing controll Maps in 3D?
Custom render styles and symbols Better label placement algorithms
Navigation modules
Offline routing with turn-by-turn navigation Offline search and geocoding
Support for other platforms
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
15
Routing with OpenStreetMap data
Data quality and coverage
High quality and coverage in metropolitan regions High quality due to imports of official or commercial data for some regions
Routing graph extraction
Conditioned on type of vehicle (e.g. car, bicycle, pedestrian) Heuristics for edge weight computation
Size of graph for different areas
Map data (OSM)
Berlin Germany Europe
Nodes
30.198 2.260.320 8.403.981
Edges
87.580 5.575.736 20.846.236
Required memory (Highway Hierarchies)
1,98 MB 123 MB 554 MB
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
16
Routing in large road networks
Beneficial properties of road networks (as routing graphs)
Vertices have low degree (~2,5 in average) Spatial information of vertices available Hierarchical structure
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
17
Highway Hierarchies Query times
HH-Routing in Germany
With DT
G0 G1 G1 G2 G2 G3 G3 G4 G4 Avg. query time: Req. memory: Preprocessing:
Nodes
2260320 818981 160058 116432 34587 28308 10127 8570 3261 2.45 ms 163 MB 131 min.
Edges
5575736 1831940 826952 387502 322354 148948 138184 67238 69252
Without DT
G0 G1 G1 G2 G2 G3 G3 G4 G4 G5 G5 G6 G6 G7 G7 G8 G8
Nodes
2260320 818981 160058 116432 34587 28308 10127 8570 3261 2826 1046 878 293 243 44 6 0
Edges
5575736 1831940 826952 387502 322354 148948 138184 67238 69252 29052 28448 4866 4690 1128 772 6 0
Avg. query time: Req. memory: Preprocessing:
3.8 ms 123 MB 157 min.
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
18
Mobile Highway Hierarchies routing
Problem: few memory graph cannot be hold in RAM minimize I/O Solution:
Partition each level of the graph into smaller blocks Utilize spatial locality property of HH-search
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
19
Thank you!
http://mapsforge.org
SplineTalks: OpenStreetMap navigation and maps on Android
mapsforge.org free mapping and navigation tools
20