Tutorial: loading a KML file using the J2memap library

By admin • avril 16th, 2008

Ok, 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:

Comments

By thomas.landspurg on avril 17th, 2008 at 11:29

Testing WP2.5 install….

I have try this and it return following error message

java.lang.IllegalArgumentException: invalid host format
at com.sun.midp.io.HttpUrl.parseAfterScheme(), bci=612
at com.sun.midp.io.HttpUrl.(), bci=33
at com.sun.midp.io.j2me.http.Protocol.openPrim(), bci=15
at javax.microedition.io.Connector.openPrim(), bci=327
at javax.microedition.io.Connector.open(), bci=3
at javax.microedition.io.Connector.open(), bci=3
at javax.microedition.io.Connector.open(), bci=2
at com.eightmotions.util.URLFetcher.open(URLFetcher.java:70)
at com.eightmotions.map.BufferImage.fetcher(), bci=384
at com.eightmotions.map.BufferImage.checkBuffer(BufferImage.java:976)
at com.eightmotions.map.BufferImage$1.run(BufferImage.java:220)
at java.lang.Thread.run(), bci=11

how can I solve that ?
Please help me …

 

Leave a Comment

« OpenCellID re-integrate GsmLoc data | Home | New cells contributions »