群集单击后缩放地图

时间:2018-05-17 09:34:35

标签: android google-maps zoom

我正在尝试在onClusterClick之后实现缩放,但我正在使用此库Link而我不知道如何操作。在谷歌图书馆

 @Override
 public boolean onClusterClick(final Cluster<MyItem> cluster) {
   map.animateCamera(CameraUpdateFactory.newLatLngZoom(
   cluster.getPosition(), (float) Math.floor(map
   .getCameraPosition().zoom + 1)), 300,null);
                return true;`

但我没有getPosition()。我只有getLatitude()getLongitude

1 个答案:

答案 0 :(得分:1)

map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(getLatitude(), getLongitude()), MY_ZOOM)

或者这个选项

LatLngBounds.Builder builder = LatLngBounds.builder();
for (SampleClusterItem item : cluster.getItems()) {
    builder.include(new LatLng(item.getLatitude(), item.getLongitude()));
}
final LatLngBounds bounds = builder.build();

try {
    mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, PADDING));
} catch (Exception e) {
    Log.e("TAG_SNAP", "onClusterClick: " + e.getMessage());
}