Вот код, который я использую:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(getZoomPoint(), 15)) ;
Код: Выделить всё
private LatLng getZoomPoint() {
Double minLatitude = null;
Double minLongitude = null;
Double maxLatitude = null;
Double maxLongitude = null;
for (Feature feature : features) {
List coordinates = ((LineString) feature.getGeometry()).getCoordinates();
for (Coordinates coordinate : coordinates) {
// --------------------------------------------------------- INITIALISATION
if (minLatitude == null) { // No matter on which var we check
minLatitude = coordinate.getLatitude();
minLongitude = coordinate.getLongitude();
maxLatitude = coordinate.getLatitude();
maxLongitude = coordinate.getLongitude();
} else {
if (coordinate.getLatitude() < minLatitude) {
minLatitude = coordinate.getLatitude();
}
if (coordinate.getLatitude() > maxLatitude) {
maxLatitude = coordinate.getLatitude();
}
if (coordinate.getLongitude() < minLongitude) {
minLongitude = coordinate.getLongitude();
}
if (coordinate.getLongitude() > maxLongitude) {
maxLongitude = coordinate.getLongitude();
}
}
}
}
double meanLatitude = (minLatitude + maxLatitude) / 2;
double meanLongitude = (minLongitude + maxLongitude) / 2;
return new LatLng(meanLatitude, meanLongitude);
}
Мой второй вопрос: как подогнать ширину полилиний в зависимости от уровня масштабирования камеры? Я добавил прослушиватель:
Код: Выделить всё
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d("ZOOM = ", "" +mMap.getCameraPosition().zoom);
});
Есть предложения?
Подробнее здесь: https://stackoverflow.com/questions/417 ... s-and-zoom
Мобильная версия