0

I have this code inside the onMapReady that sets up the lat/long along with starting the async task of prepping the overlay image.

public void onMapReady(GoogleMap googleMap) {
    mGoogleMap = googleMap;
    moveToCurrentLocation(mGoogleMap,new LatLng(49.26874005, -123.19854477));
    newarkBounds= new LatLngBounds(
            new LatLng(49.26874005, -123.19854477),       // South west corner
            new LatLng(49.27462099, -123.19069126));      // North east corner*//*
    // Adds a ground overlay with 50% transparency.

   new BitmapWorkerTask().execute();
}

here is the code prepping the image and setting it to google maps.

class BitmapWorkerTask extends AsyncTask<Integer, Void, Bitmap> {
    private int data = 0;

    public BitmapWorkerTask() {
        // Use a WeakReference to ensure the ImageView can be garbage collected

    }

    // Decode image in background.
    @Override
    protected Bitmap doInBackground(Integer... params) {
        imageDescriptor = BitmapDescriptorFactory.fromResource(R.drawable.vfmf_overlay);
        return null;
    }

    // Once complete, see if ImageView is still around and set bitmap.
    @Override
    protected void onPostExecute(Bitmap bitmap) {
        mGoogleMap.addGroundOverlay(new GroundOverlayOptions()
                .image(imageDescriptor)
                .positionFromBounds(newarkBounds));
    }
}

my current image is 63KB and when I zoom in to the max, I'm able to see the image file, which is .png, perfectly clear, but when it's zoomed out it looks like a shredded piece of paper and pieces of it are missing. However, when I use the same image when it's 332 KB, the application crashes with out of memory. Using this very same code. Any idea why this is happening?

Jay
  • 2,591
  • 1
  • 16
  • 28
  • 1
    To avoid out of memory crashes use [Tile Overlays](https://developers.google.com/maps/documentation/android-sdk/tileoverlay). – Andrii Omelchenko Jul 05 '18 at 14:07
  • @AndriiOmelchenko it says here in the link you provided: "ground overlays are useful when you wish to fix a single image at one area on the map." The image isn't covering a large piece of area, it's a park that's not even 1 square mile. Probably a third of that, so will a Tile Overlay be over kill for something like that? – Jay Jul 05 '18 at 23:18
  • "1 square mile" its not important - important image size. If you got out of memory crash on your Ground Overlay picture actually you have only 2 ways: 1) decrease resolution of image; 2) split that image into parts (Tile Overlays). Also you can use [android:largeHeap="true"](https://developer.android.com/reference/android/R.styleable#AndroidManifestApplication_largeHeap) option, but it's not good solution. – Andrii Omelchenko Jul 06 '18 at 08:16
  • Hey @AndriiOmelchenko I was only able to find this question related to what I'm trying to accomplish - however when I copy the file: CustomMapTileProvider, I'm running into compile time issues. Plus this doesn't show me how to set it up properly using a local image - do you have any sample code or articles that could point me in the right direction? https://stackoverflow.com/questions/14784841/tileprovider-using-local-tiles , – Jay Jul 10 '18 at 01:47
  • Your [link](https://stackoverflow.com/a/14833256/6950238) is complete example. And for split your image into tiles you can use [MapTiler](https://www.maptiler.com/). – Andrii Omelchenko Jul 10 '18 at 07:12
  • the problem is that in order to split my image into tiles, the product is over a grand ...there has to be an easier / cheaper way to accomplish this. – Jay Jul 10 '18 at 07:40
  • It's not as difficult as it seems. And there is no other ways only: decrease resolution of image; split that image into tiles; android:largeHeap="true". – Andrii Omelchenko Jul 10 '18 at 08:11

0 Answers0