Java me 在j2me中的location finder类中添加gauge

Java me 在j2me中的location finder类中添加gauge,java-me,geolocation,midp,lcdui,gauge,Java Me,Geolocation,Midp,Lcdui,Gauge,我正在开发一个j2me应用程序,其中包含一个使用GPS查找移动设备位置的类。在调用位置提供程序API并查找位置时,我需要包含gauge。我是j2me新手,因此仍然不清楚所有概念。我正在粘贴下面的代码。请帮助我完成此操作。提前感谢 package org.ets.utils; import javax.microedition.lcdui.*; import javax.microedition.location.*; import javax.microedition.io.*; import

我正在开发一个j2me应用程序,其中包含一个使用GPS查找移动设备位置的类。在调用位置提供程序API并查找位置时,我需要包含gauge。我是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;

    } 




}

}

LUIT 1.5在这方面可以帮助您。我不确定您正在使用的位置API。 但您将使用LWUIT 1.5获得仪表。使用LWIIT而不是LCDUI


您无法将
仪表链接到某项任务

您必须手动设置
仪表的值。因此,您需要创建一个
量表
,并将其添加到您的
表单
。然后启动代码执行查找

在代码行之间添加
myGauge.setValue(一些值)以增加指示器

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

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;
 }

}
然后,您将创建一个
量表
,并将其添加到
表单中

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);