Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art

Using a Scale on an OpenStreetMap Map

Author: Rachee Singh
Published? true -- FormatLanguage: W

Problem:

You need to show a map scale on your OSM to indicate the level of zoom on the MapView

Solution:

A scale can be added on the OSM as an overlay using the ScaleBarOverlay class

Discussion:

Putting a scale on your MapView helps the user keep track of the zoom level at which he is (also helping him/her of the approximate distances on the map). To overlay a scale on your OSM MapView, instantiate the ScaleBarOverlay and add it to your MapView using the add method.

Here is how the code would look:

ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
this.mapView.getOverlays().add(this.myScaleBarOverlay);

The scale bar overlay looks like this:

No records found.