如何默认倾斜相机而不是俯视图?

时间:2014-11-20 03:56:18

标签: android google-maps

我的片段中有mapView,我在地图上显示了很多针脚。

默认情况下,相机位于地图顶部,并从头顶显示。

通过在地图上拖动一个点 - 用两根手指 - 然后向下移动手指然后相机倾斜。

我希望默认从这个倾斜的视图中显示我的地图。

有可能吗?感谢。

=====

更新

我有以下代码行,但似乎不起作用:(

@Override
    public void onMapLoaded()
    {
        if (this.mMap != null)
        {
            CameraPosition position = new CameraPosition.Builder().tilt(30).build();
            this.mMap.animateCamera(CameraUpdateFactory.newCameraPosition(position));
        }
        // Subclass should override this to implement the feature
    }

==========

答案

对于那些有同样问题的人来说,这是我的解决方案,工作正常。

protected synchronized void animateMapTo(final LatLng pin, final Float zoomLevel, final boolean useAnimation)
    {
        final GoogleMap map = this.getMap();
        if (!this.isSafe() || pin == null || map == null)
        {
            return;
        }

        // Set zoomlevel to current level if not set.
        final float cameraZoomLevel = zoomLevel == null ? map.getCameraPosition().zoom : zoomLevel;

        // Build camera position
        CameraPosition position = new CameraPosition.Builder()
                .target(pin)
                .zoom(cameraZoomLevel)
                .bearing(0)
                .tilt(45)
                .build();

        // Stop any animations
        map.stopAnimation();
        if (useAnimation)
        {
            map.animateCamera(CameraUpdateFactory.newCameraPosition(position));
//            map.animateCamera(CameraUpdateFactory.newLatLngZoom(pin, cameraZoomLevel));
        }
        else
        {
            map.moveCamera(CameraUpdateFactory.newCameraPosition(position));
//            map.moveCamera(CameraUpdateFactory.newLatLngZoom(pin, cameraZoomLevel));
        }
    }

1 个答案:

答案 0 :(得分:0)

Build a new CameraPositioncreate a CameraUpdate from it,然后moveanimate地图相机到达该位置。