【问题标题】:How to apply Camera bounds with CameraPosition in google map如何在谷歌地图中使用 CameraPosition 应用相机边界
【发布时间】:2015-11-26 13:04:12
【问题描述】:

我需要同时使用 CameraPosition 和 CameraBounds 的一些功能,就像我的具体要求是在轴承上移动相机并将其倾斜几度,以及地图上我想要覆盖的其他标记我执行相机更新。

CameraUpdateFactory 类有两个不同的方法用于两个不同的目的。 1) newCameraPosition 2) newLatLngBounds
但我怀疑我是否可以同时使用它们来获得我想要的结果。

CameraPosition 的工作原理如下:

LatLng current_lat_lng=new LatLng(lat, lon);
        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(current_lat_lng)      // Sets the center of the map to Mountain View
        .zoom(googleMap.getCameraPosition().zoom)                   // Sets the zoom
        .bearing((float)mapHeading)                // Sets the orientation of the camera to a bearing
        .tilt(0)                   // Sets the tilt of the camera to 0 degrees
        .build();
        googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

CameraBounds 的工作方式如下:

final LatLngBounds.Builder builder = new LatLngBounds.Builder();
        if (marker_Searched != null) {
            builder.include(marker_Searched.getPosition());
        }
        if (marker_selected_taxi != null) {
            builder.include(marker_selected_taxi.getPosition());
        }   

        LatLngBounds bounds = builder.build();      
        int padding = 300; // offset from edges of the map in pixels
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
        googleMap.moveCamera(cu);

有没有人尝试过任何解决方法?

【问题讨论】:

  • 你为什么不一个接一个地使用?
  • @Androiderson :由于两次相机移动(一次具有单个位置,一次具有位置边界)而产生抖动效果
  • 为避免出现问题,请尝试在第二个上使用animateCamera

标签: android google-maps android-maps-v2


【解决方案1】:

使用 CancellableCallback 将您的相机动画到 LatLngBounds,然后在 onFinish 中获取缩放值 (map.getCameraPosition().zoom),然后将此值应用到 CameraPosition。它对我很有效。

【讨论】:

  • 一个更完整的例子会很好。
猜你喜欢
  • 2013-10-10
  • 1970-01-01
  • 1970-01-01
  • 2018-11-02
  • 2011-02-21
  • 1970-01-01
  • 1970-01-01
  • 2020-02-25
  • 1970-01-01
相关资源
最近更新 更多