谷歌地图API v2 J2ME

时间:2014-03-28 23:06:51

标签: google-maps java-me

大家好我是J2ME开发的初学者,我创建了一个小的j2me应用程序,它应该允许我根据我必须在TextField中的输入中输入的地址来定位位置,所以我根据这段代码制作了这段代码来自jappit.com的教程,但是当我启动应用程序时,屏幕在加载时被阻止,我在控制台中收到此错误:

“未捕获的异常java / lang / NumberFormatException:抱歉... body {font-family:verdana。”

这是代码:

import com.jappit.midmaps.googlemaps.GoogleMaps;
import com.jappit.midmaps.googlemaps.GoogleMapsCoordinates;
import com.jappit.midmaps.googlemaps.GoogleMapsGeocoder;
import com.jappit.midmaps.googlemaps.GoogleMapsGeocoderHandler;
import com.jappit.midmaps.googlemaps.GoogleMapsMarker;
import com.jappit.midmaps.googlemaps.GoogleStaticMap;
import com.jappit.midmaps.googlemaps.GoogleStaticMapHandler;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class MapMidlet extends MIDlet implements CommandListener{


    TextField searchbox = new TextField("Address","Enter your address here",100,TextField.ANY);
        Form menu = new Form("Search Menu");
        List type = new List("Type",List.EXCLUSIVE);
        Command search = new Command("Search",Command.OK,0);
        Command Exit = new Command("exit",Command.EXIT,1);
    Display display = Display.getDisplay(this);
    Ticker ti = new Ticker("Find me If you can !");
        Alert alert = new Alert("Please enter an address","address is missing", null, AlertType.ERROR);
     String adress;  
    public MapMidlet() {
    }

    protected void destroyApp(boolean unconditional)
             {

    }

    protected void pauseApp() {

    }

    protected void startApp()  {
      adress=searchbox.getString();
          menu.setCommandListener(this);
          menu.append(searchbox);
          menu.addCommand(search);
          menu.addCommand(Exit);
          display.setCurrent(menu);



    //display.setCurrent(new  MapCanvas(this));

    }

    public void commandAction(Command c, Displayable d) {





        if(c==search)
        {



        display.setCurrent(new MapCanvas(this));}



        else
         {notifyDestroyed();}


    }



    public class MapCanvas extends Canvas implements GoogleStaticMapHandler, GoogleMapsGeocoderHandler
{
    GoogleMaps gMaps = null;

    GoogleStaticMap map = null;

     String API_KEY = "AIzaSyBe1yXRcCXWQB_6ReSGbf0lH8XVwTvNpSQ";
    MapMidlet mid;
    public MapCanvas(MapMidlet mid)
    {

        this.mid=mid;
        gMaps = new GoogleMaps(API_KEY);

        map = gMaps.createMap(getWidth(), getHeight(), GoogleStaticMap.FORMAT_PNG);

        //map.setHandler(this);
        //map.setCenter(new GoogleMapsCoordinates(36.8189700,10.1657900));
                //map.setZoom(15);

        //map.update();

        GoogleMapsGeocoder geocoder = gMaps.createGeocoder();

        geocoder.setHandler(this);

        geocoder.geocodeAddress(adress);
    }

    protected void paint(Graphics g)
    {
        map.draw(g, 0, 0, Graphics.TOP | Graphics.LEFT);
    }

    public void GoogleMapsGeocodeError(String address, int errorCode, String errorDescription)
    {
        System.out.println("Geocode error: " + errorCode + ", " + errorDescription);
    }
    public void GoogleMapsGeocodeSuccess(String address, GoogleMapsCoordinates coordinates, int accuracy)
    {
        map.setCenter(coordinates);

        map.addMarker(new GoogleMapsMarker(coordinates));

        map.setZoom(accuracy);

        map.update();
    }
    public void GoogleStaticMapUpdateError(GoogleStaticMap map, int errorCode, String errorMessage)
    {
        System.out.println("map error: " + errorCode + ", " + errorMessage);
    }
    public void GoogleStaticMapUpdated(GoogleStaticMap map)
    {
        System.out.println("map loaded");

        repaint();
    }

}


}

感谢。

0 个答案:

没有答案