×
Namespaces

Variants
Actions
Revision as of 16:02, 9 November 2011 by skalogir (Talk | contribs)

How to create custom Map View in Java ME

From Nokia Developer 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 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 working project

As of version 0.5, Nokia Maps API for Java ME is provided as a separate library. The link 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]);
}
}
}
}

Source and Binary Files

The code above can be downloaded from File:MapsCustomViewSource.zip

The installation .jar and .jad files can be downloaded from File:MapsCustomViewBinaries.zip

See also

Nokia Maps API for Java ME


Article Metadata
Code ExampleTested with
Devices(s): X3-02
Compatibility
Device(s): All
Dependencies: Nokia Maps API for Java ME v0.5
Article
Keywords: Hybrid view, Satellite view, Normal view, Terrain view, Maps, Nokia Maps
Created: skalogir (08 Nov 2011)
Reviewed: skalogir (08 Nov 2011)
Last edited: skalogir (09 Nov 2011)
144 page views in the last 30 days.
×