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?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With