Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 09:23, 20 September 2013 by jasfox (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to create custom Map View in Java ME

From Wiki
Jump to: navigation, search

This article explains how to retrieve the available map views and apply one of them to your custom Maps by using the HERE Maps API for Java ME. This makes it possible to display a location by using aerial satellite images. Hybrid, terrain and several other modes are also available.

Normal View Satellite View Hybrid View
Normalview.png Satelliteview.png Hybridview.png
Ordinary map view with large labels for mobile Aerial photography image no labels Aerial photography image with roads and labels
Terrain View Transit View Night View
Terrainview.png Transitview.png Nightview.png
Topographical Map Map highlighting Public Transport Low glare map for night use.



HERE Maps API for Java ME uses the MapProvider class in order to display the available view modes. MapProvider is a base class used to identify a provider for layered map information. Map providers are divided into those providing data for a base map and those providing data for a transparent overlay layer that can be added on top of the base map (e.g. traffic overlay). Satellite, hybrid, terrain and normal map displays are regarded as the base map on top of which, one can add overlays. Each map mode (hybrid, satellite, normal, terrain) corresponds to one MapProvider. The MapDisplay class, supports retrieval of the available base maps, by calling the getAvailableBaseMap() method. This returns an array of MapProvider objects. Iterating through the items of the array, makes it possible to get information about the view and eventually apply it, by calling the setBaseMapType() method.

Integration of HERE Maps API for Java ME into the working project

Currently the version 1.3, HERE Maps API for Java ME is provided as a separate plug-in. For details, including documentation and the downloadable .jar file, check the "see also" link.

Implementing the mapsCustomView midlet

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
* Minimal MIDP application to show map content to the user.

public class MapTypeMIDlet extends MIDlet {
protected void startApp() throws MIDletStateChangeException {
// Insert your own AppId and Token, as obtained from the above
// URL into the two methods below.
Display display = Display.getDisplay(this);
MapTypeDemo minimalMap = new MapTypeDemo(display, this);
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {}
protected void pauseApp() {}
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
* This demonstrates Map Type usage, allowing a user to view the available map types.

public class MapTypeDemo extends MapCanvas implements MapSchemeListener, CommandListener {
private MapProvider[] mapSchemes;
private Command[] options;
private final Command EXIT = new Command("Exit", Command.EXIT, 1);
protected MIDlet midlet; // for notifyDestroyed
public MapTypeDemo(Display display, MIDlet midlet) {
this.midlet = midlet;
private void init() {
new MapDisplayState(new GeoCoordinate(51.477, 0.0, 0), 14));
* Called when the list of available map schemes has been downloaded from
* the network. This indicates that online maps are available and that the
* list of schemes returned from {@link MapDisplay#getAvailableMapOverlays() } is
* complete.

public void onMapSchemesAvailable(MapProvider[] mapSchemes) {
this.mapSchemes = mapSchemes;
options = new Command[mapSchemes.length];
for (int i = 0; i < mapSchemes.length; i++) {
String thisoption = mapSchemes[i].getName();
options[i] = new Command(thisoption, Command.HELP, 5);
private void showError(Throwable reason) {
Alert a = new Alert("ERROR", reason.toString(), null, AlertType.INFO);
display.setCurrent(a, this);
public void commandAction(final Command c, Displayable d) {
if (c == EXIT) {
} else {
for (int i = 0; i < options.length; i++) {
if (c == options[i]) {
try {
} catch (IllegalArgumentException iae) {
public void onMapContentComplete() {
// No code required.
public void onMapUpdateError(String description, Throwable detail, boolean critical) {
public void onMapSchemesError(Throwable reason) {

Source and Binary Files

The code above can be downloaded from

The installation .jar and .jad files can be downloaded from

Article Metadata
Code ExampleTested with
Devices(s): X3-02, Asha 305, Asha 311, Asha 501
Device(s): All
Dependencies: HERE Maps API for Java ME v1.3
Keywords: Hybrid view, Satellite view, Normal view, Terrain view, Maps, HERE Maps, Java ME, custom map, view
Created: skalogir (08 Nov 2011)
Reviewed: skalogir (08 Nov 2011)
Last edited: jasfox (20 Sep 2013)
This page was last modified on 20 September 2013, at 09:23.
106 page views in the last 30 days.