1

I have this code

        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        builder.include(mainLocation);
        builder.include(userLocation);
        LatLngBounds bounds = builder.build();
        CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
        mMap.animateCamera(cu);

And this works it shows bounds but i would like to show bounds on the top half of the screen (is there a way to put offset y?).

enter image description here

(Hope this picture will explain things better)

MePo
  • 1,044
  • 2
  • 23
  • 48

4 Answers4

2

If I understand you correctly, what you get now is that map is centered, meaning your provided locations are centered on the map. And you want those locations to be on the upper part of the screen.

It seems there is not such an API, that would allow to apply padding to bottom only.

You can add a fake location to LatLngBounds.Builder at the lower part of the screen, now the CameraUpdate would include that point also, which will shift your 2 real points on the upper part.

azizbekian
  • 60,783
  • 13
  • 169
  • 249
0

You can use the setPadding method from the GoogleMap object.

In your case you will need to add a bottom padding:

mMap.setPadding(0, 0, 0, 150);
antonio
  • 18,044
  • 4
  • 45
  • 61
0

Maybe late, but i solved this. I make bottom padding for map, before call animateCamera, and return padding after update.

val heightValue = (Resources.getSystem().displayMetrics.heightPixels * 0.5).toInt()
map.setPadding(0,0,0,heightValue)

 val update = CameraUpdateFactory.newLatLngBounds(bounds,50)

 map.animateCamera(update,object:GoogleMap.CancelableCallback{
            override fun onFinish() {
                inUi {
                    map.setPadding(0,0,0,0)
                }
            }

            override fun onCancel() {}
        })
0

Here is the best solution I found to achieve this effect. You force the padding you need before animating the camera, and immediately after, you reset the padding to whatever ever value.

map.setPadding(left, top, right, bottom) // In your example, this will be the only non-zero value.
animateCamera(cameraUpdate) // Trigger the animation
map.setPadding(0, 0, 0, 0) // Reset the padding
Simon Marquis
  • 7,248
  • 1
  • 28
  • 43