更改偏移量

通過根據需要更改 mappoint xy 值,你可以更改 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)));
        }