Monday, January 17, 2011

Map Operation --Set Map Type

After create the instance of RasterMap, you can move, zoom in, zoom out or set different type of map.
In the first example, When call RasterMap.setCenter, you can specify the map type. Besides RasterMap.setMapType can be used to change map type. There are more than 20 buildin map types, include Google map, Bing map, Bing Satellite map etc.
The following example change map type from Google Map, Bing Map to CloudMade Map (OpenStreet Map).
public class MapTypeMIDP extends MapDemoMIDP implements CommandListener {

    private int mapType = 0;
    private static final int[] mapTypes = {MapType.GOOGLEMAP,
        MapType.MICROSOFTMAP, MapType.OPENSTREETMAP};    private Command mapTypeCommand = new Command("MapType", Command.OK, 1);

    public void startApp() {

        init();
        canvas.addCommand(mapTypeCommand);
        canvas.setCommandListener(this);
        GeoLatLng center = new GeoLatLng(-31.948275, 115.857562);
        map.setCenter(center, 13, MapType.GOOGLEMAP);        Display.getDisplay(this).setCurrent(canvas);
    }

    public void commandAction(Command c, Displayable d) {
        if (c == mapTypeCommand) {
            map.setMapType(mapTypes[mapType]);
            mapType++;
            mapType %= mapTypes.length;
        }
    }
}




No comments:

Post a Comment