Tutorial: loading a KML file using the J2memap library
Wednesday, April 16th, 2008Ok, following some requests, here is another tutorial on how to use the J2memap library. First, note that if you just want to display a KML file on mobile, you can use 8Motions directly, no need to create your own application.
Anyway, here we are going to show you how to create a very simple app that display a KML file on a cell phone. First, download the J2memap library (you need to be registered to download it), and put thelibraryCLDC11.jar (or 10.jar) as a library of your project. In netbeans, you do Properties,add jar/zip,select the jar file.
Here I take a KML file, but it could be also a GPX file, LOC or GEORSS file….
Then, here is the code:
package com.eightmotions.LoadTrack; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import com.eightmotions.util.*; import com.eightmotions.map.*; /** * * @author tlandspurg * @version */ public class LoadTrack extends MIDlet implements TrackNotifier { MapCanvas m_map; Display m_display; public void startApp() { UtilMidp.checkMIDP(this); //Initialise the utility library... // Initialize the map, get the display, and put the map on it m_map=new MapCanvas(); m_display=Display.getDisplay(this); m_display.setCurrent(m_map); // Load a track, and display this track to a map Track track=Track.getTrack(m_display,"http://www.8motions.com/map/showKml/107","Loading Track",m_map); // Listen for track loaded event... track.setNotifier(this); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } /* When the track has been loaded, display it... */ public void onTrackLoaded(Track tr) { m_map.displayTrack(tr,true); } public void onTrackCreated(Track t) { }; public void onTrackSaved(Track t) {}; }
Here is the result:
