0

我正在开发一个 j2me 应用程序,其中包含一个使用 GPS 查找移动设备位置的类。我需要在调用位置提供程序 API 并找到位置时包含仪表。我是 j2me 的新手,所以仍然不清楚所有概念。我在下面粘贴我的代码。请帮助我完成这个。在此先感谢..

package org.ets.utils;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;
import javax.microedition.io.*;
import java.io.*;
import org.ets.midlet.ETS_infozech;
import javax.microedition.midlet.*;


public class Locfinder  {






public Locfinder(ETS_infozech midlet)
{
    this.midlet = midlet;


}

public static String ex()
    {

        try {


                     checkLocation();
                    } catch (Exception ex)
                    {
                        ex.printStackTrace();

        }
        //System.out.println(string);
        return string;

    }

public static void  checkLocation() throws Exception
{

    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 = " LAT-" + lat + " LONG-" + lon;

    } 




}

}

4

2 回答 2

0

LWUIT 1.5 可以在这方面为您提供帮助。不确定您正在使用的 Location API。但是您将使用 LWUIT 1.5 获得 Gauge。使用 Lwuit 而不是 LCDUI。

http://www.oracle.com/technetwork/java/javame/javamobile/download/lwuit/index.html

于 2014-05-15T10:55:02.713 回答
0

您无法将 a 链接Gauge到某个任务。

您必须Gauge手动设置值。因此,您将创建一个Gauge并将其添加到您的Form. 然后启动您的代码以执行查找。

在您的代码行之间,您将添加myGauge.setValue(some_value);以增加指标。

当然,当大部分任务都包含在一行代码中时,这会变得很困难,例如lp.getLocation(60);. 我认为,在这种情况下,我会创建一个在 60 秒内Thread自动增加值的值Gauge,但可以通过手动设置停止/覆盖。

class Autoincrementer implements Runnable {

private boolean running;
private Gauge gauge;
private int seconds;
private int secondsElapsed;

 public Autoincrementer(Gauge gauge) {
  this.gauge = gauge;
  this.seconds = gauge.getMaxValue();
  this.running = true;
  this.secondsElapsed = 0;
 }

 public void run() {

  if (running) {
   secondsElapsed++;
   gauge.setValue(secondsElapsed);
   if (secondsElapsed>=gauge.getMaxValue()) running = false; // Stop the auto incrementing
   try {
    Thread.sleep(1000); // Sleep for 1 second
   } catch (Exception e) {}
  }
 }

 public void stop() {
  running = false;
 }

}

然后,您将创建一个Gauge并将其添加到您的Form

myGauge = new Gauge("Process", false, 60, 0);
myForm.append(myGauge);

然后启动自动增量。

myIncrementer = new Autoincrementer(myGauge);
new Thread(myIncrementer).start();

然后调用您的查找代码。

checkLocation();

在您的查找代码中,添加代码以停止自动递增并将Gauge对象设置为 100%,如果查找成功(意味着在超时之前)。

myIncrementer.stop();
myGauge.setValue(60);
于 2014-05-15T13:42:46.057 回答