0

我正在尝试设置 mylocationoverlay。不幸的是,它的行为很奇怪。它工作正常,只是在我离开 MapActivity 并回到我的应用程序之后才会出现。最初,地图出现并且有一个蓝色圆圈,而它正在获得一个很好的位置。然而,圆圈并没有解决到一个点,而是消失了。

我的代码如下所示:

onResume() {
    myLocation = new MyLocationOverlay(getActivity(), mp);
myLocation.enableMyLocation();
myLocation.runOnFirstFix(new Runnable(){
       public void run() {
          map.getOverlays().clear();
      map.getOverlays().add(myLocation);
      map.postInvalidate();
       }
    }
}


onPause() {
  myLocation.disableMyLocation();
  layout.removeView(map);
  map = null;

}

有人对这里可能发生的事情有任何想法吗?由于这几乎是所有在线示例的逐字记录,我可能会补充一点,我正在运行 2.3.4 的 motorolla atrix 上进行测试。

4

1 回答 1

0

Edit :让我带你看看你的代码:

onResume() {
// First time: draw a circle somewhere here. There is no GPS fix yet, so no dot. 
// Second time: The dot from the previous fix exists, so you get a circle and dot.
myLocation = new MyLocationOverlay(getActivity(), mp);
myLocation.enableMyLocation();
myLocation.runOnFirstFix(new Runnable(){
       public void run() {
       // First time: removes the circle and draws a dot.
       // Second time: removes the circle and dot, and draw a new dot. 
       map.getOverlays().clear();
       map.getOverlays().add(myLocation);
       map.postInvalidate();
       }
    }
}

map.getOverlays().clear();删除圆圈

remove()改为删除您不想要的覆盖,而不是全部清除。

map.invalidate();记得在需要强制重绘时调用

于 2011-10-21T03:43:25.767 回答