Search code examples
mapboxviewportmapbox-androidmapbox-ios

How do I get the viewport in pixels in Mapbox?


How do I get the viewport of the Camera in pixels Android / iOS? I'm trying to use padding to shift the viewport but how do I get the size of viewport?

Current code, hard-coding 1300 which most likely won't work on other screen sizes this is why I need the viewport's size

double[] padding = {0, 1300, 0, 0};
return new CameraPosition.Builder()
    .padding(padding)
    .target(center)
    .bearing(getDirectionForUserLocationUpdate())
    .tilt(mPitch)
    .zoom(zoomLevel)
    .build();

Solution

  • Class MapView has a method getHeight() that's how you can retrieve the height.