0

我有一个计算某个位置的纬度和经度的后台进程。然后我使用计时器任务每隔几秒运行一次以获取计算出的纬度和经度并显示在 RichMapField 上。我需要在地图上显示这个纬度和经度,但由于计时器的原因,它没有显示出来。有人可以告诉我如何处理这种情况。

编辑:只是给一个更好的理解:下面是我的代码:

每 5 秒安排一次的计时器:

    timer.scheduleAtFixedRate(new TimerTask() {
          public void run()
          {
              currentLocation.run();
          }}, 0, 5000); 



  public Runnable currentLocation = new Runnable()
 {
  public void run() {
        double[] coordinates = new double[3];
        coordinates[0]= 47.674131297119935;
        coordinates[1]= 9.384496898485185;
        coordinates[2]= 475.678;
        addToMap(coordinates);          
  }

 };

public void addToMap(double[] coordinates)
{
       MapLocation location1 = new MapLocation(coordinates[0],coordinates[1],"My Location2",null);
       int location1ID = data.add((Mappable)location1,"My");
       data.tag(location1ID, "Location1");

       MapLocation location2 = new MapLocation(coordinates[0],coordinates[1],"My Location2",null);
       int location2ID = data.add((Mappable)location2,"My");
       data.tag(location2ID, "Location2");
}
4

0 回答 0