mylocationoverlay 第一次找到位置时消失

发布于 2024-12-10 20:22:56 字数 665 浏览 0 评论 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 上测试它。

I am trying to setup a mylocationoverlay. Unfortunately, it is acting quite strangely. It works fine, except it does not appear until after I leave the MapActivity and come back in my application. Initially the map appears and there is a blue circle while it is getting a fine location. However, instead of resolving to a point, the circle just disappears.

My Code looks like this:

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;

}

Does anyone have any thoughts on what might be happening here? Since this is pretty much verbatim what all the examples online look like, I might add that I am testing this on a motorolla atrix running 2.3.4.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浴红衣 2024-12-17 20:22:56

编辑:让我带您浏览一下您的代码:

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

Edit : Let me take you through your code:

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(); removes the circle

use remove() instead to remove the overlay(s) that you don't want, instead of clearing them all.

Remember to call map.invalidate(); whenever you need to force a redraw

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文