Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect my position is no longer shown on map (after navigation)?

I want to add a button in map that center the map on user current position, but it should be activated only if the user navigate in map and his current position is no longer displayed on map. to detect the navigation I used the onTouchEvent method.

 @Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {

Log.e("Touch", Integer.toString(event.getAction()));

int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
    touchStarted = true;
} else if (action == MotionEvent.ACTION_MOVE) {

   if (event.getPointerCount() > 3)
     moveStarted = true;
    return true;

}
return true;
}

but how I detect that my current position is no longer on screen?

like image 633
DaRkNight Avatar asked Oct 22 '13 23:10

DaRkNight


1 Answers

Actually i found a better solution:

private void CheckVisibility(Marker myPosition)
{
    if(googleMap != null)
    {
        //This is the current user-viewable region of the map
        LatLngBounds bounds = googleMap.getProjection().getVisibleRegion().latLngBounds;

            if(bounds.contains(myPosition.getPosition()))
                   //If the item is within the the bounds of the screen

            else
                  //If the marker is off screen
    }
}
like image 177
DaRkNight Avatar answered Oct 18 '22 00:10

DaRkNight