Android 在 Fling 上获取 Mapview 停止动画

发布于 2024-11-06 08:22:36 字数 500 浏览 0 评论 0原文

我需要限制用户可以在地图视图中导航到的区域(除非他们会看到空白屏幕!)。 我创建了一个扩展地图视图并覆盖 onTouchEvent 的类。 我正在检测“ACTION_UP”操作并检查此处的坐标,并在必要时重新定位地图。一切正常,直到用户“扔”地图。我可以检测到“向上”和此时屏幕的坐标,但地图仍在移动,因此我检测到的坐标不是正确的。

我需要知道屏幕停止移动时的位置!

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP ) {
//get coords of screen corners and calculate if the map is still in view.
}

我一直在寻找这个问题的答案,但很多人都在问这个问题,但似乎没有任何解决方案?

有人设法做到这一点吗?

贝克斯

I need to limit the area my users can navigate to in the mapview (unless they'll get a blank screen!).
I have created a class that extends the mapview and overridden the onTouchEvent.
I am detecting the action "ACTION_UP" and checking the coords here and repostioning the map if I have to. Everything works fine until the user "flings" the map. I can detect the "Up" and the coordinates of the screen at that point, but the map is still moving so the coordinates I detect aren't the correct ones.

I need to know the screen position when it's stopped moving!

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP ) {
//get coords of screen corners and calculate if the map is still in view.
}

I have been looking for a fair amount of time for the answer to this but lots of people are asking the question, but there don't appear to be any solutions around?

Has anyone managed to do this?

Bex

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

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

发布评论

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

评论(2

将军与妓 2024-11-13 08:22:36

我用来重写 MapView 的computeScroll() 方法:

/**
 * checks restriction on pan bounds and locks the map. if the map is locked
 * (via mapController.getCenter()) this method returns true
 * 
 * @return TRUE if map has been locked
 */
private boolean restrictPanOnBounds() {
  if (this.minLatitudeE6 == Integer.MIN_VALUE)
    return false;

  GeoPoint center = getMapCenter();
  int cLat = center.getLatitudeE6();
  int cLong = center.getLongitudeE6();

  Integer nLat = null, nLong = null;

  if (cLat < this.minLatitudeE6)
    nLat = this.minLatitudeE6;
  else if (cLat > this.maxLatitudeE6)
    nLat = this.maxLatitudeE6;

  if (cLong < this.minLongitudeE6)
    nLong = this.minLongitudeE6;
  else if (cLong > this.maxLongitudeE6)
    nLong = this.maxLongitudeE6;

  if (nLat != null || nLong != null) {
    getController().setCenter(new GeoPoint(nLat != null ? nLat : cLat, nLong != null ? nLong : cLong));
    return true;
  } else {
    return false;
  }
}

@Override
public void computeScroll() {
  if (restrictPanOnBounds())
    getController().stopPanning();
  else
    super.computeScroll();
}

它对于简单的移动动作非常有效(地图停止不会跳回),但在投掷时仍然具有“有趣的”倾斜效果......

i use to override the computeScroll() method of the MapView:

/**
 * checks restriction on pan bounds and locks the map. if the map is locked
 * (via mapController.getCenter()) this method returns true
 * 
 * @return TRUE if map has been locked
 */
private boolean restrictPanOnBounds() {
  if (this.minLatitudeE6 == Integer.MIN_VALUE)
    return false;

  GeoPoint center = getMapCenter();
  int cLat = center.getLatitudeE6();
  int cLong = center.getLongitudeE6();

  Integer nLat = null, nLong = null;

  if (cLat < this.minLatitudeE6)
    nLat = this.minLatitudeE6;
  else if (cLat > this.maxLatitudeE6)
    nLat = this.maxLatitudeE6;

  if (cLong < this.minLongitudeE6)
    nLong = this.minLongitudeE6;
  else if (cLong > this.maxLongitudeE6)
    nLong = this.maxLongitudeE6;

  if (nLat != null || nLong != null) {
    getController().setCenter(new GeoPoint(nLat != null ? nLat : cLat, nLong != null ? nLong : cLong));
    return true;
  } else {
    return false;
  }
}

@Override
public void computeScroll() {
  if (restrictPanOnBounds())
    getController().stopPanning();
  else
    super.computeScroll();
}

it works quite well for simple move actions ( the map stops has does not jump back ) but still has a "funny" tilt effect when flinging...

黯然 2024-11-13 08:22:36

我也有同样的问题。你的方法很好,只需要在另一个地方赶上事件即可。您可以重写 MapView 类的“DispatchTouchEvent”方法(或使用 MapFragment 采取类似的方法),并使其跳过 MotionEvent.ACTION_UP 事件:

if (ev.getAction() == MotionEvent.ACTION_UP ) {
   return false;
}

I had the same problem. Your approach is good, just need to catch the event on another place. You can override "DispatchTouchEvent" method of MapView class (or take similar approach using MapFragment), and there you make it skip MotionEvent.ACTION_UP event:

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