How to determine my position is no longer displayed on the map (after navigation)?

I want to add a button on the map that centers the map at the user's current position, but it should be activated only if the user moves around the map and his current position is no longer displayed on the map. I used the onTouchEvent method to detect navigation.

  @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 do I find that my current position is no longer displayed on the screen?

+6
source share
2 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 } } 
+9
source

My best idea on how to do this is to first find out what the camera is pointing to (i.e. what the user sees). Then do some math to pinpoint what a camera is in terms of LatLng and compare it with the user's current location.

An alternative suggestion would be to simply use the included My Location Button as part of the API. It will always be visible, but it will be the same as the Google Maps application, so your users will already understand how to interact with it.

0
source

Source: https://habr.com/ru/post/956515/


All Articles