我正在尝试在地图上设置用户位置,使其位于距离屏幕底部大约1/3的位置,当地图旋转时,它将围绕此点旋转。
我最接近实现这一点的方法是使用setPadding()
方法,然而,这会导致地图在旋转时进行抖动,因为中心点会“漂浮”在实际应该的位置。它看起来很难看
int mapHeight = mapView.getHeight();
googleMap.setPadding(0, mapHeight / 5, 0, 0);
有一个更好的方法吗?
编辑:如下图所示
你不需要填充
根据需要更改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)));
}
输出:
接受的答案可能是“animateCamera”的作品。它使“旋转摇晃”几乎看不见。所以更容易使用
mMap.setPadding(leftPx,topPx,rightPx,bottomPx)
使用mMap.animateCamera或两次mMap.moveCamera(如果更换轴承1和moveCamera旋转设备中心,第二个moveCamera使用填充制作正确的中心)
它是一种黑客攻击,而谷歌不考虑setPadding固定轮换