varios studio puntos marcar marcadores google example ejemplo custom agregar android google-maps android-maps

puntos - map fragment android studio



Android: establecer el nivel de zoom en Google Maps para incluir todos los puntos de Marker (3)

Estoy tratando de establecer el nivel de zoom para Maps en Android de modo que incluya todos los puntos en mi lista. Estoy usando el siguiente código.

int minLatitude = Integer.MAX_VALUE; int maxLatitude = Integer.MIN_VALUE; int minLongitude = Integer.MAX_VALUE; int maxLongitude = Integer.MIN_VALUE; // Find the boundaries of the item set // item contains a list of GeoPoints for (GeoPoint item : items) { int lat = item.getLatitudeE6(); int lon = item.getLongitudeE6(); maxLatitude = Math.max(lat, maxLatitude); minLatitude = Math.min(lat, minLatitude); maxLongitude = Math.max(lon, maxLongitude); minLongitude = Math.min(lon, minLongitude); } objMapController.zoomToSpan( Math.abs(maxLatitude - minLatitude), Math.abs(maxLongitude - minLongitude));

esto funciona a veces Sin embargo, algunas veces, algunos puntos no se muestran y, a continuación, necesito alejar para ver esos puntos. ¿Hay alguna manera de resolver este problema?


Descubrí la respuesta yo mismo, el nivel de Zoom fue correcto. Necesito agregar el siguiente código para mostrar todos los puntos en la pantalla.

objMapController.animateTo(new GeoPoint( (maxLatitude + minLatitude)/2, (maxLongitude + minLongitude)/2 ));

El punto central no estaba correctamente alineado creando un problema para mí. Esto funciona.


Otro enfoque más con Android Map API v2:

private void fixZoom() { List<LatLng> points = route.getPoints(); // route is instance of PolylineOptions LatLngBounds.Builder bc = new LatLngBounds.Builder(); for (LatLng item : points) { bc.include(item); } map.moveCamera(CameraUpdateFactory.newLatLngBounds(bc.build(), 50)); }


Parte del problema podría ser que MIN_VALUE sigue siendo un número positivo, pero las latitudes y longitudes pueden ser números negativos. Intenta usar NEGATIVE_INFINITY en lugar de MIN_VALUE.