2

This post is very similar to This, which does not currently have a solution (3 years old)

The main issue is that GoogleMaps seems to be adding an unnecessary amount of padding around my ground overlay image this doesn't make sense to me since the boundaries are set to the same lat,lngs as the ground overlay.

@Override
public void onMapReady(GoogleMap googleMap) {

    final LatLngBounds NewarkBounds = new LatLngBounds(
            new LatLng(FILL, -FILL),
            new LatLng(FILL, -FILL)
    );

    mMap = googleMap;
    mMap.getUiSettings().setMapToolbarEnabled(false);
    mMap.getUiSettings().setZoomGesturesEnabled(false);
    mMap.getUiSettings().setMyLocationButtonEnabled(false);

    LatLng myPosition = new LatLng(latitude,longitude);


    GroundOverlayOptions newarkMap = new GroundOverlayOptions()
            .image(BitmapDescriptorFactory.fromResource(R.drawable.maptest))
            .positionFromBounds(NewarkBounds)
            .visible(true);

    mMap.addGroundOverlay(newarkMap);



    if((myPosition.latitude <= FILL&& myPosition.latitude >=FILL) && (myPosition.longitude >= -FILL&& myPosition.longitude <= -FILL)){
        mMap.setMyLocationEnabled(true);

    }
    else {
        mMap.setMyLocationEnabled(false);
    }

    mMap.setOnMyLocationButtonClickListener(this);
    mMap.setOnMyLocationClickListener(this);
    mMap.setMapType(0);


    /*
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;
    int padding = (int) (width * 0.001); // offset from edges of the map 12% of screen

    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(NewarkBounds, width, height, 0);
    mMap.animateCamera(cu);
    mMap.setPadding(0,0,0,0);
    mMap.setLatLngBoundsForCameraTarget(NewarkBounds);
    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NewarkBounds.getCenter(), 17));
    // Set the camera to the greatest possible zoom level that includes the bounds

    */

    mMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
        @Override
        public void onMapLoaded() {
            // Set the camera to the greatest possible zoom level that includes the bounds
            mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(NewarkBounds, 0));
            //Centering the camera within bounds:
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(NewarkBounds.getCenter(), 17));
            //Restricting the user's scrolling and panning within bounds:
            mMap.setLatLngBoundsForCameraTarget(NewarkBounds);
        }
    });
}

I have tried multiple methods to fix this, I found it is possible to assign different coordinates outside of the bounds to the ground overlay but this is simply incorrect. Below is what the current display shows.

enter image description here

This is what I want to achieve

enter image description here

I would appreciate any thoughts on this issue as it is driving me bonkers. Thank you!

Dumbledore
  • 95
  • 6
  • Hey just wanted to mention that I am looking into this and will get back to you next week! – evan Feb 21 '20 at 16:15
  • 1
    Hey Evan, appreciate it. I think it's something to do with specific mobile devices and how much padding is added but I might be wrong! – Dumbledore Feb 23 '20 at 14:16
  • Hey can you please test this with the beta version 3.0 of the SDK? Does the same issue occur? https://developers.google.com/maps/documentation/android-sdk/v3-client-migration – evan Mar 03 '20 at 09:09
  • This beta is supposed to fix many issues from version 2. Looking forward to your update! – evan Mar 03 '20 at 09:10
  • 1
    Hi Evan, I will have a look at this and let you know :) thanks a bunch for spending your time helping me – Dumbledore Mar 06 '20 at 14:44
  • Hi Dumbledore did you try this out? Please keep me posted. :) – evan Mar 24 '20 at 11:07
  • 1
    Hi Evan, sorry for not getting back to you. I did try it out. unfortunately, I could still not get the desired outcome I wanted. Luckily I've spoken with the people I'm writing this for and they are not bothered by this issue. Thank you for all the help x – Dumbledore Mar 25 '20 at 19:42
  • I see, bummer. At least I'm glad you no longer need a quick fix for this! – evan Mar 26 '20 at 08:44

0 Answers0