【问题标题】:Android Google Maps - Get current tilt, bearing and zoomAndroid Google Maps - 获取当前倾斜、方位和缩放
【发布时间】:2015-07-25 21:43:05
【问题描述】:

我正在谷歌地图上构建一个安卓应用,它显示用户的当前位置,并不断更新。

现在,我想要的是,如果作为用户,我缩小地图并改变方位,我希望我的相机保持该缩放、方位和倾斜。

这是我目前使用的 -

public void setupLocationOnMap(){
        if (mLastLocation != null) {
            LatLng myLatLng = new LatLng(mLastLocation.getLatitude(),mLastLocation.getLongitude());

            if(firstTimeSetup) {
                cameraPosition = new CameraPosition.Builder().target(myLatLng).zoom(17).bearing(-30).tilt(30).build();
                firstTimeSetup = false;
            } else {
                cameraPosition = new CameraPosition.Builder().target(myLatLng).build();
            }
            mMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }
    }

这个函数在 onLocationChanged(Location location) 回调中被调用。我想要实现的是,在“其他”部分,如果用户更改了他的变焦或方位,我想在相机中保持该变焦、方位和倾斜。我不想在每次更新位置时将相机设置为某个预定义的值。我想获取当前的缩放、方位和倾斜,并将相机设置为,只有 (lat,lang) 需要更新。

非常感谢任何帮助。

【问题讨论】:

    标签: android google-maps google-maps-android-api-2


    【解决方案1】:

    您可以获取当前相机位置并使用这些值:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.html#getCameraPosition()

    获取相机的当前位置。 返回的CameraPosition 是当前位置的快照,不会在相机移动时自动更新

    所以你可以这样做:

    CameraPosition currentposition=googlemap.getCameraPosition();
    currentposition.tilt
    currentposition.bearing
    currentposition.zoom
    

    您现在拥有所有需要的值!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-27
      • 2012-06-13
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多