更改Google地图抵消中心

Dpo*_*ogy 9 android google-maps offset

我正在尝试在地图上设置用户位置,使其位于距离屏幕底部大约1/3的位置,当地图旋转时,它将围绕此点旋转.

我最接近实现这一点的setPadding()方法是使用这种方法,然而,这会导致地图在旋转时进行抖动,因为中心点会"浮动"在实际应该的位置.它看起来很难看

int mapHeight = mapView.getHeight();
googleMap.setPadding(0, mapHeight / 5, 0, 0);
Run Code Online (Sandbox Code Playgroud)

有一个更好的方法吗?

编辑:如下图所示

在此输入图像描述

Cha*_*ruක 19

你不需要填充

根据需要更改mappoint X和Y值,您可以在任意位置调用它!可能在你的onLocationChanged喜欢 里面changeOffsetCenter(location.getLatitude(),location.getLongitude());

 public void changeOffsetCenter(double latitude,double longitude) {
            Point mappoint = mGoogleMap.getProjection().toScreenLocation(new LatLng(latitude, longitude));
            mappoint.set(mappoint.x, mappoint.y-100); // change these values as you need , just hard coded a value if you want you can give it based on a ratio like using DisplayMetrics  as well
            mGoogleMap.animateCamera(CameraUpdateFactory.newLatLng(mGoogleMap.getProjection().fromScreenLocation(mappoint)));
        }
Run Code Online (Sandbox Code Playgroud)

输出:

在此输入图像描述