Android Get Mapview on Fling stopped animation

I need to limit the area in which my users can navigate in mapview (unless they get a blank screen!). I created a class that extends mapview and overrides onTouchEvent. I discovered the action "ACTION_UP" and checked the coordinates and retelling of the map here, if necessary. Everything works fine until the user “ejects” the card. I can detect the Up and screen coordinates at this point, but the map is still moving, so the detected coordinates are not correct.

I need to know the position of the screen when it stops 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 was looking for quite a while to answer this question, but many people ask a question, but there are no solutions around?

Could anyone do this?

Bex

+3
2

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

( ), "" ...

0

. , . "DispatchTouchEvent" MapView ( MapFragment), MotionEvent.ACTION_UP:

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

All Articles