¿Cómo puedo determinar si se muestra un geopunto en el área visible actualmente?
Decir que tengo el control de mapa en mi aplicación para Android. Si sé que existe un punto de referencia en una cierta latitud y longitud, ¿cómo puedo determinar si ese punto de referencia está actualmente visible en la pantalla del usuario? ¿Existe un método para obtener las coordenadas de las esquinas superior izquierda e inferior derecha del área visible?
- Marcador arrastrable de Android MapView
- Resolvamos el error "Error al encontrar estilo 'mapViewstyle' en tema actual"
- Android Rotación de MapView
- Inhabilitar el movimiento en mapview
- Mapview y Fragmento
- Eliminar todas las superposiciones
- El alias Keytool no existe
- ¿Cómo conservar una vista de mapa dentro de un fragmento?
- ¿Cómo puedo dibujar una flecha que muestre la dirección de manejo en MapView?
- Android cómo obtener temprature de la ubicación en mapview
- ¿Debo usar MapView o MapFragment
- Clustering marcadores en android mapas v2
- onTouchEvent nunca llamado MapActivity
Puede proyectar GeoPoint a punto y comprobar si es cuadro (0, anchura de pantalla) por (0, altura de pantalla)
Consulta: https://developer.android.com/reference/com/google/android/gms/maps/Projection.html
Algo como esto hará el truco.
private boolean isCurrentLocationVisible() { Rect currentMapBoundsRect = new Rect(); Point currentDevicePosition = new Point(); GeoPoint deviceLocation = new GeoPoint((int) (bestCurrentLocation.getLatitude() * 1000000.0), (int) (bestCurrentLocation.getLongitude() * 1000000.0)); mapView.getProjection().toPixels(deviceLocation, currentDevicePosition); mapView.getDrawingRect(currentMapBoundsRect); return currentMapBoundsRect.contains(currentDevicePosition.x, currentDevicePosition.y); }
Uniéndose a los consejos aquí , aquí y aquí :
Aquí está el código completo de mi CustomMapView:
package net.alouw.alouwCheckin.ui.map; import android.content.Context; import android.util.AttributeSet; import android.util.Pair; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; /** * @author Felipe Micaroni Lalli ([email protected]) */ public class CustomMapView extends MapView { public CustomMapView(Context context, String s) { super(context, s); } public CustomMapView(Context context, AttributeSet attributeSet) { super(context, attributeSet); } public CustomMapView(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); } /** * * @return a Pair of two pairs with: top right corner (lat, lon), bottom left corner (lat, lon) */ public Pair<Pair<Double, Double>, Pair<Double, Double>> getMapCorners() { GeoPoint center = getMapCenter(); int latitudeSpan = getLatitudeSpan(); int longtitudeSpan = getLongitudeSpan(); double topRightLat = (center.getLatitudeE6() + (latitudeSpan / 2.0d)) / 1.0E6; double topRightLon = (center.getLongitudeE6() + (longtitudeSpan / 2.0d)) / 1.0E6; double bottomLeftLat = (center.getLatitudeE6() - (latitudeSpan / 2.0d)) / 1.0E6; double bottomLeftLon = (center.getLongitudeE6() - (longtitudeSpan / 2.0d)) / 1.0E6; return new Pair<Pair<Double, Double>, Pair<Double, Double>>( new Pair<Double, Double>(topRightLat, topRightLon), new Pair<Double, Double>(bottomLeftLat, bottomLeftLon)); } }
Ok, ya que me tomó algún tiempo ahora para encontrar una solución de trabajo simple voy a publicar aquí para todos después de mí;) En su propia subclase de MapView sólo tiene que utilizar lo siguiente:
GeoPoint topLeft = this.getProjection().fromPixels(0, 0); GeoPoint bottomRight = this.getProjection().fromPixels(getWidth(),getHeight());
Eso es todo, entonces usted puede obtener las coordenadas a través de
topLeft.getLatitudeE6() / 1E6 topLeft.getLongitudeE6() / 1E6
y
bottomRight.getLatitudeE6() / 1E6 bottomRight.getLongitudeE6() / 1E6
- Android Emulator no funciona en Ubuntu después de actualizar Android Studio a 2.0 – Biblioteca Qt no encontrada
- Reproductor de video en pantalla completa – mediacontroller detrás de la barra de navegación