更改偏移量
通过根据需要更改 mappoint x 和 y 值,你可以更改 Google 地图的偏移量,默认情况下它将位于地图视图的中心。请在下面调用你想要更改的方法! 最好在 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)));
}