Kunta Kinte
Kunta Kinte

Reputation: 371

Android maps padding and map bounds

I'm using android maps v2, I'm using a padding to move the map controls and the logo of google:

       mMap.setPadding(0, 0, 0, padding_in_px);

On the other hand I need to know what are the limits of the visible part of the map:

       LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;

The problem is that if I put a padding, the function does not return me the bounds of the visible region on the map, but only the bounds of the visible region minus the padding region.

Is there any way that when the map has padding mMap.getProjection().getVisibleRegion() returns the actual visible bounds and not the map bounds - the padding bounds?

Thanks

Upvotes: 6

Views: 2046

Answers (1)

ztan
ztan

Reputation: 6921

The LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds; can give you the nearLeft and nearRight properties, they are LatLng type.

You can convert either nearLeft or nearRight to a screen point, by using toScreenLocation(). Once you get the bottom point of your visible region, you can use that point plus the padding pixels you put (ex: 100, padding_in_px). Then you can convert back the point back using fromScreenLocation().

LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
LatLng nearLeft = bounds.nearLeft
Point visibleNearLeftPoint =  mMap.getProjection().toScreenLocation(nearLeft);
Point screenBottomLeftPoint = new Point(visibleNearLeftPoint.x, visibleNearLeftPoint.y + padding_in_px);
LatLng screenBottomLatLng = mMap.getProjection().fromScreenLocation(screenBottomLeftPoint);

Upvotes: 8

Related Questions