Skip to content Skip to sidebar Skip to footer

Android Google Maps Groundoverlay From Bitmap Appears White

I am trying to display a ground overlay downloaded from url. the problem is that the image is not shown and the overlay appears as white square. thinking the Bitmap Object is fault

Solution 1:

It may be a problem of using large images means higher resolution. It could be suggested by your log cat so can you paste your log cat here.

OR

Try using Tile Overlay instead of ground overlay.

OR

use this code which worked for me in same problem..

import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentManager;
    import android.util.Log;
    import android.util.TypedValue;
    import android.view.Menu;
    import android.view.MenuItem;





    publicclassMapDisplayActivityextendsFragmentActivityimplementsOnMapClickListener, OnMapLongClickListener  {
    private GoogleMap myMap;

    privatestatic  LatLng SearchPlace;
    double Latitude;
    double Longitiude;
    List<Address> addresses;

    //Address location;
    BitmapDescriptor image;
/// private static final LatLng NEWARK = new LatLng(18.5236, 73.8478);private GroundOverlay mGroundOverlay;

        //this is for omnistarg dont touch this 
        LatLng southwest= newLatLng(-85.513398,-178.242187);

        LatLng northeast= newLatLng(85.513398,178.242187);

     floatzoomValue=7.0f;
    private String SpinerValue;
    private Bitmap bitmap;
        @Override
        `enter code here`protectedvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapactivity);
    //VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
    Log.v("Utils", "Max mem in MB : " +    (Runtime.getRuntime().maxMemory()/(1024*1024)));
    Runtime.getRuntime().maxMemory();
    Debug.getNativeHeapSize();

    initActionBar();

    //textInfo=(TextView)findViewById(R.id.locinfo);FragmentManagermyFragmentManager= getSupportFragmentManager();
       SupportMapFragmentmySupportMapFragment= (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
       myMap = mySupportMapFragment.getMap();





      // myMap.setMyLocationEnabled(true);// myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
       myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      // myMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);//myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);


       myMap.setOnMapClickListener(this);
       myMap.setOnMapLongClickListener(this);
       myMap.getUiSettings().setZoomControlsEnabled(true);
       myMap.getUiSettings().setMyLocationButtonEnabled(true);

       Intent intent=getIntent();
       Latitude=intent.getDoubleExtra("Latitude", 0.000);
       Longitiude=intent.getDoubleExtra("Longititude", 0.000);
       SpinerValue=(String)intent.getStringExtra("SPINNERVALUE");

       SearchPlace = newLatLng(Latitude, Longitiude);

       myMap.moveCamera(CameraUpdateFactory.newLatLng(SearchPlace));
       myMap.addMarker(newMarkerOptions().position(SearchPlace));//.title(PlaceName));
       drawImageOverMap();




}



publicvoiddrawImageOverMap(){

       myMap.animateCamera(CameraUpdateFactory.zoomTo(zoomValue));

            //image =BitmapDescriptorFactory.fromResource(R.drawable.omnistar_g);if(SpinerValue.equalsIgnoreCase("TEC")){
           //centerpoint_vrs
           bitmap =   (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    //.transparency(0.4f)//.anchor(0, 1)
                    .positionFromBounds(bounds));

       }
       elseif(SpinerValue.equalsIgnoreCase("OmniSTARG2")){
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_g_img);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       elseif(SpinerValue.equalsIgnoreCase("OmniStarHP")){
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_hp_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       /////////////////////////////////////////////elseif(SpinerValue.equalsIgnoreCase("OmniStarVBS")){
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_vbs_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));

       }
       elseif(SpinerValue.equalsIgnoreCase("OmniSTARXP")){
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.omnistar_xp_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       elseif(SpinerValue.equalsIgnoreCase("RTXStandardviaCellular")){
          //rtxcell 
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_cell_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       elseif(SpinerValue.equalsIgnoreCase("RTXFastviaSatellite")){
           //rtxfast.png
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_fast_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       elseif(SpinerValue.equalsIgnoreCase("RTXStandardviaSatellite")){
           //rtxsat.png
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.rtx_sat_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
       elseif(SpinerValue.equalsIgnoreCase("VRSNow")){
           //vrsnowtec.png
           bitmap = (Bitmap)BitmapFactory.decodeResource(this.getResources(), R.drawable.vrsnow_tec_two);


            BitmapFactory.Optionso2=newBitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBoundsbounds=newLatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(newGroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

                    //.anchor(0, 1)
                    .positionFromBounds(bounds));
       }
                    // InputStream is =getClass().getResourceAsStream(omnistar_g);//bitmap = readAssetsBitmap("omnistar_g.png");//bitmap =  BitmapFactory.decodeResource(this.getResources(), R.drawable.trimble_screen_logo);//bitmap=bitmap(is);//image =BitmapDescriptorFactory.fromResource(R.drawable.omnistar_g);


                             bitmap.recycle();
                             bitmap = null;
                             System.gc();
                             Runtime.getRuntime().gc(); 



}

Post a Comment for "Android Google Maps Groundoverlay From Bitmap Appears White"