Change Google Map Offset Center

I'm trying to set the user's location on the map so that it is about 1/3 of the way up from the bottom of the screen, and when the map rotates, it will rotate around this point.

The closest I managed to achieve was to use the setPadding() method, however, this causes the map to sort the jitter when turning, as the center point โ€œfloatsโ€ around where it really should be. It looks pretty ugly

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

Is there a better way to do this?

Edit : explained in the image below.

enter image description here

+7
android google-maps offset
source share
1 answer

You do not need gaskets

Change the values โ€‹โ€‹of Mappoint X and Y as you need, you can call it wherever you want! may be inside your onLocationChanged as 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))); } 

output:

enter image description here

+13
source share

All Articles