gpt4 book ai didi

android - 更改谷歌地图偏移中心

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:23:57 24 4
gpt4 key购买 nike

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

我最接近的方法是使用 setPadding() 方法,但是,这会导致 map 在旋转时摇晃,因为中心点有点像“ float ”在它实际应该在的地方附近。看起来很丑

int mapHeight = mapView.getHeight();
googleMap.setPadding(0, mapHeight / 5, 0, 0);

有更好的方法吗?

编辑:如下图解释

enter image description here

最佳答案

你不需要填充

根据需要更改 map 点 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)));
}

输出:

enter image description here

关于android - 更改谷歌地图偏移中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41811983/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com