Let's assume at the center of the map is the Eiffel Tower, when I change the bottom padding to half of the screen height, the Eiffel Tower keeps at it's position. What I want is to move the Eiffel Tower to middle of upper half of the screen. Can someone help me?
Based from this documentation, you can add padding around the edges of the map using the GoogleMap.setPadding()
method. The map will continue to fill the entire container, but text and control positioning, map gestures, and camera movements will behave as if it has been placed in a smaller space.
Here is my sample code:
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setPadding(0,0,0,1000);
LatLng eiffel = new LatLng(48.858093, 2.294694);
mMap.moveCamera(CameraUpdateFactory.newLatLng(eiffel));
mMap.addMarker(new MarkerOptions().position(eiffel).title("Marker in Eiffel"));
}
Here is the screenshot:
Without padding:
With padding:
As you can see, I have set a padding at the bottom and the Google logo is on the middle of the screen which proves that the padding is working. The marker is also at the middle of upper screen.
You can also check on this video tutorial the way on how to use map padding with the Google Maps Android API.
Hope it helps! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With