Refresh overlay object in Map Activity on Android

♀尐吖头ヾ 提交于 2019-12-06 04:26:20

mapView.postInvalidate() will update the map view and redraw the overlays. I'm using this with a Runnable to refresh my overlays every second:

private Handler handler = new Handler();

private Runnable refreshTask = new Runnable()
{
  public void run()
  {
    handler.removeCallbacks(this);

    mapView.postInvalidate();

    handler.postDelayed(this, 1000);

  }
};

That might not be perfect but it worked for me, you may move the map a bit forth and back, which updates all overlays afterwards.

mapView.getController().scrollBy(1, 1);
mapView.getController().scrollBy(-1, -1);

When you add or remove an overlayItem you need to call populate() in your MarkerOverlay class.

Use

MapController.notifyRepaint();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!