Android Get Mapview on Fling停止动画制作

Android Get Mapview on Fling停止动画制作,android,google-maps,android-mapview,Android,Google Maps,Android Mapview,我需要限制我的用户可以在mapview中导航到的区域(除非他们得到一个空白屏幕!)。 我创建了一个扩展mapview并覆盖onTouchEvent的类。 我正在检测“action_UP”动作,并检查这里的坐标,如果有必要,我会重新定位地图。在用户“扔”地图之前,一切正常。我可以检测到“向上”和屏幕在该点的坐标,但地图仍在移动,因此我检测到的坐标不是正确的 我需要知道屏幕停止移动时的位置 @Override public boolean onTouchEvent(MotionEve

我需要限制我的用户可以在mapview中导航到的区域(除非他们得到一个空白屏幕!)。 我创建了一个扩展mapview并覆盖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.
}
我一直在寻找这个问题的答案,但很多人都在问这个问题,但似乎没有任何解决办法

有人做到了吗


Bex

我用于覆盖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();
}
/**
*检查平移边界的限制并锁定贴图。如果地图被锁定
*(通过mapController.getCenter())此方法返回true
* 
*@如果地图已锁定,则返回TRUE
*/
私有布尔限制PanonBounds(){
if(this.minLatitudeE6==Integer.MIN_值)
返回false;
地理点中心=getMapCenter();
int cLat=center.getLatitudeE6();
int cLong=center.getLongitudeE6();
整数nLat=null,nLong=null;
if(cLatthis.maxLatitudeE6)
nLat=this.maxLatitudeE6;
if(cLongthis.maxLongitudeE6)
nLong=this.maxLongitudeE6;
if(nLat!=null | | nLong!=null){
getController().setCenter(新的地质点(nLat!=null?nLat:cLat,nLong!=null?nLong:cLong));
返回true;
}否则{
返回false;
}
}
@凌驾
public void computeScroll(){
if(restrictPanOnBounds())
getController().stopPanning();
其他的
super.computeScroll();
}

对于简单的移动动作(地图停止时没有向后跳),它非常有效,但投掷时仍然有“有趣的”倾斜效果…

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

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

是的,遗憾的是,标准的
gesturedector
提供了关于放纵何时开始的信息,而不是放纵何时结束的信息。我会看一看,看是否能很容易地发现一次放纵的结局。您可以覆盖
onFling
,然后从那里返回
false
来禁用fling。此外,最好在发生
动作\u MOVE
事件时检查地图的位置,而不是向上事件,否则如果你抬起手指移动到远处,地图将“跳”回它的位置。@Joseph谢谢你的评论!如果你能看看是否有可能结束这场狂欢,那将是非常棒的!如果不能做到这一点,在一次放纵中禁用可能是最好的选择!我已经添加了手势侦听器。。但这场狂欢活动没有发生?!是的,很抱歉,在查看源代码后,很明显MapView使用了自己的手势系统,并且没有从SDK实现
GestureDetector
。你可能有点卡住了。。。编辑:当用户抬起手指时,你可以尝试
MapController
stopAnimation
stopAnimation
方法,看看是否停止了投掷。我成功地停止了投掷,我使用了错误的侦听器!它使它显得相当笨重!如果你能发现锅的末端,事情就会变得容易多了!:)