首页 > 解决方案 > 根据方位旋转谷歌地图,中心有固定标记

问题描述

我正在尝试在我的应用程序中实现谷歌地图。

要求:

驾驶时,我的标记图标应固定在屏幕中心(始终朝北),而地图应在用户打开街道时左右移动并旋转。

我是如何尝试做到的

        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 5));

        float bearing = getBearing(Lastposition,newPosition);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(newPosition)
                .zoom(15)
                .bearing(bearing)
                .tilt(0)
                .build();

        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));



    public static float getBearing(LatLng from, LatLng to) {

    Location fromLocation = new Location("");//provider name is unnecessary
    fromLocation.setLatitude(from.latitude);
    fromLocation.setLongitude(from.longitude);

    Location toLocation = new Location("");//provider name is unnecessary
    toLocation.setLatitude(to.latitude);
    toLocation.setLongitude(to.longitude);
    Log.i("Bearing",fromLocation.bearingTo(toLocation)+"");
    return fromLocation.bearingTo(toLocation);
}

结果:

标记在路径上移动,但摄像头本身不会根据驾驶员在街道上的转弯移动。我希望我能够让事情变得可以理解。请帮助解决可能出现的问题或更好的解决方案。谢谢

标签: androidgoogle-mapsgpslatitude-longitudemarker

解决方案


推荐阅读