从位图Android版谷歌地图的GroundOverlay出现白色 [英] Android Google Maps GroundOverlay from Bitmap appears white

查看:166
本文介绍了从位图Android版谷歌地图的GroundOverlay出现白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示来自URL下载地面叠加层。

问题是,该图像未显示的并叠加显示为白色正方形

想着位图对象是错误的我测试:


  1. addding相同的位图对象标记 - 标记显示o.k


  2. 获得与 .fromResource(R.id.myimage)图片 - 叠加显示o.k


但我的形象是从下载的位图对象。

这是我的code:

 私人无效addOverlayFromBitmap(位图bmImage){
        BitmapDesc​​riptor图像= BitmapDesc​​riptorFactory.fromBitmap(bmImage);
        //图像= BitmapDesc​​riptorFactory.fromResource(R.drawable.radaraimage9);        //设置锚
        经纬度NE_ANCHOR =新的经纬度(34.516481,37.679488);
        经纬度SW_ANCHOR =新的经纬度(29.474814,31.876530);        //设置边界
        的LatLngBounds边界=新的LatLngBounds(SW_ANCHOR,NE_ANCHOR);        //追加叠加到地图 - 图像显示为白色正方形
        map.addGroundOverlay(新的GroundOverlayOptions()
             在图像配(图)
             .positionFromBounds(边界)
             .transparency((浮点)0.5));        //添加标记进行调试 - 形象出现精
        map.addMarker(新的MarkerOptions()
                .POSITION(NORTH_EAST_ANCHOR)
                .icon(图)
                );
}

在AsyncTask的:

 私有类LoadRadarImageryTask扩展的AsyncTask<弦乐,太虚,位图> {
    位图bmImage;    公共LoadRadarImageryTask(){
        超();
    }    保护位图doInBackground(字符串的URL ...){
        字符串URL =网址[0];
        位图图像= NULL;
        尝试{
            在的InputStream =新的java.net.URL(URL).openStream();
            图像= BitmapFactory.de codeStream(中);
        }赶上(例外五){
            Log.e(错误,e.getMessage());
            e.printStackTrace();
        }
        返回形象;
    }    保护无效onPostExecute(位图图像​​){
        addOverlayFromBitmap(图片);
    }
}


解决方案

这可能是使用大图像的问题意味着更高的分辨率。它可以通过你的日志猫会建议这样,可以在这里贴上你的日志猫。

试着用瓷砖覆盖,而不是地面叠加的。

使用code这在同样的问题为我工作。

 进口android.support.v4.app.FragmentActivity;
    进口android.support.v4.app.FragmentManager;
    进口android.util.Log;
    进口android.util.TypedValue;
    进口android.view.Menu;
    进口android.view.MenuItem;    公共类MapDisplayActivity扩展FragmentActivity实现OnMapClickListener,OnMapLongClickListener {
    私人GoogleMap的MYMAP;    私有静态经纬度SearchPlace;
    双纬度;
    双Longitiude;
    清单<地址>地址;    //地址位置;
    BitmapDesc​​riptor形象;
///私有静态最后的经纬度纽瓦克=新的经纬度(18.5236,73.8478);
        私人地面叠加mGroundOverlay;        //这是omnistarg别碰这
        西南地区的LatLng =新经纬度(-85.513398,-178.242187);        东北的LatLng =新经纬度(85.513398,178.242187);     浮zoomValue = 7.0f;
    私人字符串SpinerValue;
    私人位图位图;
        @覆盖
        `输入code here`protected无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.mapactivity);
    //VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
    Log.v(utils的,马克斯纪念品在MB:+(调用Runtime.getRuntime()maxMemory()/(1024 * 1024)));
    调用Runtime.getRuntime()maxMemory()。
    Debug.getNativeHeapSize();    initActionBar();    //textInfo=(TextView)findViewById(R.id.locinfo);       FragmentManager myFragmentManager = getSupportFragmentManager();
       SupportMapFragment mySupportMapFragment
        =(SupportMapFragment)myFragmentManager.findFragmentById(R.id.map);
       MYMAP = mySupportMapFragment.getMap();      // myMap.setMyLocationEnabled(真);
      // 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(本);
       myMap.setOnMapLongClickListener(本);
       myMap.getUiSettings()setZoomControlsEnabled(真)。
       myMap.getUiSettings()setMyLocationButtonEnabled(真)。       意向意图= getIntent();
       纬度= intent.getDoubleExtra(纵横,0.000);
       Longitiude = intent.getDoubleExtra(Longititude,0.000);
       SpinerValue =(字符串)intent.getStringExtra(SPINNERVALUE);       SearchPlace =新的经纬度(纬度,Longitiude);       myMap.moveCamera(CameraUpdateFactory.newLatLng(SearchPlace));
       myMap.addMarker(新的MarkerOptions()位置(SearchPlace)); //标题(地名));
       drawImageOverMap();
}公共无效drawImageOverMap(){       myMap.animateCamera(CameraUpdateFactory.zoomTo(zoomValue));            //图像= BitmapDesc​​riptorFactory.fromResource(R.drawable.omnistar_g);
       如果(SpinerValue.equalsIgnoreCase(TEC)){
           // centerpoint_vrs
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.omnistar_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    //.transparency(0.4f)                    //.anchor(0,1)
                    .positionFromBounds(边界));       }
       否则如果(SpinerValue.equalsIgnoreCase(OmniSTARG2)){
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.omnistar_g_img);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.4f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       否则如果(SpinerValue.equalsIgnoreCase(OmniStarHP)){
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.omnistar_hp_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.4f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       /////////////////////////////////////////////
       否则如果(SpinerValue.equalsIgnoreCase(OmniStarVBS)){
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.omnistar_vbs_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.4f)                    //.anchor(0,1)
                    .positionFromBounds(边界));       }
       否则如果(SpinerValue.equalsIgnoreCase(OmniSTARXP)){
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.omnistar_xp_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.4f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       否则如果(SpinerValue.equalsIgnoreCase(RTXStandardviaCellular)){
          // rtxcell
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.rtx_cell_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.3f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       否则如果(SpinerValue.equalsIgnoreCase(RTXFastviaSatellite)){
           //rtxfast.png
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.rtx_fast_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.3f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       否则如果(SpinerValue.equalsIgnoreCase(RTXStandardviaSatellite)){
           //rtxsat.png
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.rtx_sat_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.3f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
       否则如果(SpinerValue.equalsIgnoreCase(VRSNow)){
           //vrsnowtec.png
           位=(位图)BitmapFactory.de codeResource(this.getResources(),R.drawable.vrsnow_tec_two);
            BitmapFactory.Options O2 =新BitmapFactory.Options();
             o2.inSampleSize = 4;
             图像= BitmapDesc​​riptorFactory.fromBitmap(位图);
                的LatLngBounds边界=新的LatLngBounds(西南,东北);
                mGroundOverlay = myMap.addGroundOverlay(新的GroundOverlayOptions()
                    在图像配(图)
                    .transparency(0.3f)                    //.anchor(0,1)
                    .positionFromBounds(边界));
       }
                    // InputStream为=的getClass()的getResourceAsStream(omnistar_g)。
                    //位图= readAssetsBitmap(omnistar_g.png);
                     //位= BitmapFactory.de codeResource(this.getResources(),R.drawable.trimble_screen_logo);
                     //位=位图(是);
                     //图像= BitmapDesc​​riptorFactory.fromResource(R.drawable.omnistar_g);
                             bitmap.recycle();
                             位= NULL;
                             System.gc()的;
                             调用Runtime.getRuntime()GC()。}

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 faulty i tested:

  1. addding the same bitmap Object to a marker - the marker shows o.k

  2. get an image with .fromResource(R.id.myimage) - the overlay shows o.k

but my image is from downloaded Bitmap Object.

This is my code:

private void addOverlayFromBitmap(Bitmap bmImage){
        BitmapDescriptor image = BitmapDescriptorFactory.fromBitmap(bmImage);
        //image = BitmapDescriptorFactory.fromResource(R.drawable.radaraimage9);

        //Set Anchors
        LatLng NE_ANCHOR = new LatLng(34.516481,37.679488);
        LatLng SW_ANCHOR = new LatLng(29.474814,31.876530);

        //Set Bounds
        LatLngBounds bounds = new LatLngBounds(SW_ANCHOR,NE_ANCHOR);

        // Append Overlay to map - image appears as white square
        map.addGroundOverlay(new GroundOverlayOptions()
             .image(image)
             .positionFromBounds(bounds)
             .transparency((float) 0.5));

        //add marker for debugging - image appears fine
        map.addMarker(new MarkerOptions()
                .position(NORTH_EAST_ANCHOR)
                .icon(image)
                );
}

The AsyncTask:

private class LoadRadarImageryTask extends AsyncTask<String, Void, Bitmap> {
    Bitmap bmImage;

    public LoadRadarImageryTask() {
        super();
    }

    protected Bitmap doInBackground(String... urls) {
        String url = urls[0];
        Bitmap image = null;
        try {
            InputStream in = new java.net.URL(url).openStream();
            image = BitmapFactory.decodeStream(in);
        } catch (Exception e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return image;
    }

    protected void onPostExecute(Bitmap image) {
        addOverlayFromBitmap(image);
    }
}

解决方案

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;





    public class MapDisplayActivity extends FragmentActivity implements         OnMapClickListener, OnMapLongClickListener  {
    private GoogleMap myMap;

    private static  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= new LatLng(-85.513398,-178.242187);

        LatLng northeast= new LatLng(85.513398,178.242187);

     float zoomValue = 7.0f;
    private String SpinerValue;
    private Bitmap bitmap;
        @Override
        `enter code here`protected void onCreate(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);

       FragmentManager myFragmentManager = getSupportFragmentManager();
       SupportMapFragment mySupportMapFragment 
        = (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 = new LatLng(Latitude, Longitiude);

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




}



public void drawImageOverMap(){

       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.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    //.transparency(0.4f)

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

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

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

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.4f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .image(image)
                    .transparency(0.3f)

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


            BitmapFactory.Options o2 = new BitmapFactory.Options();
             o2.inSampleSize=4;
             image=BitmapDescriptorFactory.fromBitmap(bitmap);
                LatLngBounds bounds =new LatLngBounds( southwest,  northeast);


                mGroundOverlay  = myMap.addGroundOverlay(new GroundOverlayOptions()
                    .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(); 



}

这篇关于从位图Android版谷歌地图的GroundOverlay出现白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆