J2ME GPS定位JSR 179实例2
//为何在模拟器上OK,在手机上就不行呢?
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
class MyCanvas extends Canvas
{
GISMIDlet GIS;
public MyCanvas(GISMIDlet GIS)
{
this.GIS = GIS;
}
private double lat;
private double lon;
public void setInfo(double lat, double lon)
{
this.lat = lat;
this.lon = lon;
}
protected void paint(Graphics g)
{
// TODO 自动产生方法 Stub
Font f = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_SMALL);
g.setFont(f);
// use font height as a line height
int lineHeight = f.getHeight();
// current line counter
int line = 0;
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x0000ff);
g.drawString("Lat, Lon (" + GIS.formatDouble(lat, 5) + ", " + GIS.formatDouble(lon, 5) + ")", 0, lineHeight * (line++), Graphics.TOP | Graphics.LEFT);
}
}
public class GISMIDlet extends MIDlet implements CommandListener, LocationListener
{
private Command exitCmd = new Command("Exit", Command.EXIT, 1);
//private Form mainForm;
private MyCanvas myCanvas;
protected double lat; // 纬度
protected double lon; // 经度
//private LocationProvider locationProvider;
//private TextField latField; // 緯度欄位
//private TextField lonField; // 經度欄位
public GISMIDlet()
{
/* mainForm = new Form("GIS 經緯度測試");
latField = new TextField("緯度:", formatDouble(lat, 5), 15,
TextField.DECIMAL); // 設定緯度欄位格式
lonField = new TextField("經度:", formatDouble(lon, 5), 15,
TextField.DECIMAL); // 設定經度欄位格式
mainForm.append(latField); // 增加緯度欄位
相关新闻>>
- 发表评论
-
- 最新评论 更多>>