本j2me程序负责获取gps定位信息,来自国外论坛,还未经过验证,仅供参考。
import java.io.*; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.Enumeration; //import java.util.Hashtable; import javax.microedition.location.*; public class Location extends MIDlet implements CommandListener { String error = ""; private static Display display = null; private Command exitCmd=new Command("Exit",Command.EXIT, 1); protected void startApp() throws MIDletStateChangeException { display = Display.getDisplay(this); System.out.println("loading"); LocationProvider lp=null; javax.microedition.location.Location location=null; try { lp= LocationProvider.getInstance(null); } catch(LocationException e) { addError(e); } try { //timeout location = lp.getLocation(20); } catch(LocationException e) { addError(e); } catch(InterruptedException e) { addError(e); } String res="[RESULTS]/n"; try{ Coordinates coordinates = location.getQualifiedCoordinates(); res+="Altitude:"+coordinates.getAltitude()+"/n"; res+="Latitude:"+coordinates.getLatitude()+"/n"; res+="Longitude:"+coordinates.getLongitude()+"/n"; }catch(Exception e){ addError(e); } Form f = new Form("Results"); f.append(res); f.append(error); f.addCommand(exitCmd); f.setCommandListener(this); display.setCurrent(f); } void addError(Exception e){ e.printStackTrace(); error+=e.getMessage()+"/n"; } public void commandAction(Command c,Displayable d) { if(c==exitCmd) { notifyDestroyed(); } } protected void pauseApp() { } protected void destroyApp(boolean unconditional) throws MIDletStateChangeException { } }
下面这段程序来自一个国外j2me的博客。
JAVA: import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.location.*; public class loctest extends MIDlet implements CommandListener { private Display display; private Form form; private Command cmdExit,cmdOK; private StringItem si; public loctest() { display =Display.getDisplay(this); form = new Form("Location Api test"); cmdExit = new Command("Exit",Command.EXIT,5); cmdOK = new Command("OK",Command.OK,1); si = new StringItem("Geo Location", "Click OK"); form.append(si); form.addCommand(cmdOK); form.addCommand(cmdExit); form.setCommandListener(this); } public void startApp() { display.setCurrent(form); } public void pauseApp() { } public void destroyApp(boolean flag) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { if (c == cmdOK){ Retriever ret = new Retriever(this); ret.start(); } else if (c == cmdExit) { destroyApp(false); } } public void displayString(String string) { si.setText(string); } } class Retriever extends Thread { private loctest midlet; public Retriever(loctest midlet) { /** * Constructor * * EFFECTS: Initialise the server and store midlet information * * @param midlet The main application midlet * @param server Forecast Server URL * */ this.midlet = midlet; } public void run() { /** * Entry point of the thread * * EFFECTS: call to connect() method */ try { checkLocation(); } catch (Exception ex) { ex.printStackTrace(); midlet.displayString(ex.toString()); } } public void checkLocation() throws Exception { String string; Location l; LocationProvider lp; Coordinates c; // Set criteria for selecting a location provider: // accurate to 500 meters horizontally Criteria cr= new Criteria(); cr.setHorizontalAccuracy(500); // Get an instance of the provider lp= LocationProvider.getInstance(cr); // Request the location, setting a one-minute timeout l = lp.getLocation(60); c = l.getQualifiedCoordinates(); if(c != null ) { // Use coordinate information double lat = c.getLatitude(); double lon = c.getLongitude(); string = "/nLatitude : " + lat + "/nLongitude : " + lon; } else { string ="Location API failed"; } midlet.displayString(string); } }
@EnableXxx註解 Spring有很多@EnableXxx這種形式的註解,類似於可以一鍵打開某項功能,相當於暴露給用戶的一種便捷的配置API,例如 @EnableAsync 激活異步執行能力,@EnableTransactionMan
本教程將指導您如何生成一個可運行的Google Web Toolkit (GWT) 2.1和Spring應用程序,該應用程序爲域模型實現了CRUD應用程序模式。在本教程中,您將學習如何: 安裝Google Eclipse插件 爲GWT配置
CountDownLatch 是 Java 中的一個同步工具類,它允許一個或多個線程等待一系列指定操作執行完成。CountDownLatch 的主要方法有兩個:await() 方法等待 countDown 方法被調用指定的次數後繼續執行,c
導讀 本文主要講解了MVEL表達式和責任鏈設計模式相結合一起的消息處理解決方案設計、解耦消息處理節點以及方便代碼維護擴展。通過“訂單拆單消息”的接入作爲具體實踐案例,簡要闡述了MVEL表達式和Apache Chain職責鏈設計模式應用場景。
Java將List結果分成3份執行 在Java編程中,有時候我們需要將一個List集合中的元素分成幾部分進行處理。這種情況下,我們可以使用Java的相關類庫和API來實現這一需求。在本文中,我們將介紹如何使用Java將List結果分成3份執
隨着業務的發展,文件數量和文件大小會急劇增加,文件遷移的數量和難度不斷攀升。oss_pipe 是rust編寫的文件遷移工具,旨在支撐大規模的文件遷移場景。 編寫 oss_pipe 的初衷 •同類產品面臨的問題 •rust 語
轉載自tuoluzhe8521 導讀:通過簡化複雜的任務依賴關係, DolphinScheduler爲數據工程師提供了強大的工作流程管理和調度能力。在3.2.0版本中,DolphinScheduler帶來了一系列新功能和改進,使其在生產環
微服務Gateway 微服務網關部署在前端Nginx網關和後端微服務之間,Nginx一般充當流量網關,而微服務網關屬於一種業務型 網關,微服務網關層爲後端的微服務羣組提供統一的接入地址,其核心功能是統一做服務路由,在路由基礎上還 可以實現一
本文分享自華爲雲社區《JDBC連接openGauss6.0和PostgreSQL16.2性能對比》,作者: Gauss松鼠會小助手。 PostgreSQL vs openGauss 01 前置準備 安裝JDK: 詳細安裝步驟請問度娘,輸
1 前言: 大家都知道,阿里規範中有一條是不允許用excutors去創建線程池,而是採用ThreadPoolExecutor的原生方式去創建。很早就聽過所過這種說法,但是一直都沒去搞清楚是爲什麼,今天就查閱資料去了解了這
Ai technology 前言 AppBuilder上線了低代碼製作組件功能,可以通過工作流的方式構建自定義組件,完成簡單Agent無法完成的複雜功能,使得生成的文本更加定製化,
Vite 預構建的核心原理 1. 兼容性與性能的雙重目標 Vite 的預構建旨在解決兩個主要問題:兼容性和性能。對於兼容性,由於 Vite 在開發階段將所有代碼視爲原生 ES 模塊,因此需要將 CommonJS 或 UMD 格式的依賴轉
自動裝配原理分析 條件註冊機制 spring-context模塊中有兩個組件:Condition接口和@Conditional註解,在@Conditional註解中可以指定一組Condition實現, 通常@Conditional是和@Co
條件註冊 Spring 4.0 引入條件註冊機制,暴露給用戶的API是@Conditional和Condition接口,把@Conditional聲明在一個 @Component類上,並接受一組條件(Condition實現),容器初始化期間
本文分享自華爲雲社區《Python函數與模塊的精髓與高級特性》,作者:檸檬味擁抱。 Python 是一種功能強大的編程語言,擁有豐富的函數和模塊,使得開發者能夠輕鬆地構建複雜的應用程序。本文將介紹 Python 中函數和模塊的基本使用方法,