How to create custom Map View in Java ME
This article explains how to retrieve the available map views and apply one of them to your custom Maps by using Nokia Maps API for Java ME. This makes it possible to display a location by using aerial satellite images. Hybrid and terrain modes are also available.
Contents |
Introduction
Nokia 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, allows to get information about the view and eventually apply it, by calling the setBaseMapType method.
Integration of Nokia Maps API for Java ME into the project
As of version 0.5, Nokia Maps API for Java ME is provided as a separate library. The link provided at the bottom of this page, redirects to the location where the API, including documentation and the .jar file, can be downloaded.
Implementing the mapsCustomView midlet
import com.nokia.maps.map.MapCanvas;
import com.nokia.maps.map.MapDisplay;
import com.nokia.maps.map.MapFactory;
import com.nokia.maps.map.MapProvider;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.*;
public class mapsCustomView extends MIDlet implements CommandListener
{
Display display;
MapCanvas mapcanvas;
MapDisplay mapdisplay;
MapProvider[] providers;
MapFactory mapfactory;
ChoiceGroup allBaseMaps;
Command parentCommand;
Command[] options;
public void startApp()
{
display=Display.getDisplay(this);
mapcanvas = new MapCanvas(display);
mapdisplay=mapcanvas.getMapDisplay();
providers=mapdisplay.getAvailableBaseMap();
options=new Command[providers.length];
for(int i=0;i<providers.length;i++)
{
String thisoption=providers[i].getName();
options[i]=new Command(thisoption,Command.HELP,5);
mapcanvas.addCommand(options[i]); }
display.setCurrent(mapcanvas);
mapcanvas.setCommandListener(this);
}
public void pauseApp()
{ }
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable arg1)
{
for(int i=0;i<options.length;i++)
{
if(c==options[i])
{
mapdisplay.setBaseMapType(providers[i]);
}
}
}
}
See also
Article Metadata
Code Example
Tested with
Compatibility
Article

