Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android谷歌地图地面覆盖从位图显示为白色_Android_Google Maps_Bitmap - Fatal编程技术网

Android谷歌地图地面覆盖从位图显示为白色

Android谷歌地图地面覆盖从位图显示为白色,android,google-maps,bitmap,Android,Google Maps,Bitmap,我试图显示从url下载的地面覆盖图 问题是图像没有显示,覆盖显示为白色正方形 认为位图对象有故障,我测试了: 将同一位图对象添加到标记-标记显示OK 使用.fromResource(R.id.myimage)获取图像-覆盖显示正常 但我的图像是从下载的位图对象 这是我的代码: private void addOverlayFromBitmap(Bitmap bmImage){ BitmapDescriptor image = BitmapDescriptorFactory.fro

我试图显示从url下载的地面覆盖图

问题是图像没有显示,覆盖显示为白色正方形

认为位图对象有故障,我测试了:

  • 将同一位图对象添加到标记-标记显示OK

  • 使用
    .fromResource(R.id.myimage)
    获取图像-覆盖显示正常

  • 但我的图像是从下载的位图对象

    这是我的代码:

    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)
                    );
    }
    
    异步任务:

    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);
        }
    }
    
    私有类LoadRadarImageryTask扩展异步任务{
    位图图像;
    公共加载雷达管理任务(){
    超级();
    }
    受保护位图doInBackground(字符串…URL){
    字符串url=url[0];
    位图图像=空;
    试一试{
    InputStream in=new java.net.URL(URL.openStream();
    image=BitmapFactory.decodeStream(in);
    }捕获(例外e){
    Log.e(“Error”,e.getMessage());
    e、 printStackTrace();
    }
    返回图像;
    }
    受保护的void onPostExecute(位图图像){
    addOverlayFromBitmap(图像);
    }
    }
    
    使用大图像意味着更高的分辨率可能是个问题。它可能是由您的日志猫建议的,因此您可以将日志猫粘贴到此处

    尝试使用瓷砖覆盖而不是地面覆盖

    请使用在同一问题中对我起作用的代码

    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.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{
    私人谷歌地图;
    私人静态停车场;
    双纬度;
    双纵;
    列出地址;
    //地址位置;
    位图描述符图像;
    ///专用静态最终车床纽瓦克=新车床(18.5236,73.8478);
    私人地面覆盖;
    //这是给omnistarg的别碰这个
    LatLng西南=新LatLng(-85.513398,-178.242187);
    LatLng东北=新LatLng(85.513398178.242187);
    浮动zoomValue=7.0f;
    私有字符串SpinerValue;
    私有位图;
    @凌驾
    `在此处输入代码`protectedvoid onCreate(Bundle 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(true);
    //setMapType(GoogleMap.MAP\u TYPE\u HYBRID);
    myMap.setMapType(GoogleMap.MAP\u TYPE\u NORMAL);
    //myMap.setMapType(GoogleMap.MAP\u-TYPE\u卫星);
    //myMap.setMapType(GoogleMap.MAP\u TYPE\u地形);
    myMap.setOnMapClickListener(这个);
    myMap.setOnMapLongClickListener(这个);
    myMap.getUiSettings().setZoomControlsEnabled(true);
    myMap.getUiSettings().setMyLocationButtonEnabled(true);
    Intent=getIntent();
    纬度=意图。getDoubleExtra(“纬度”,0.000);
    Longitiude=intent.getDoubleExtra(“Longititude”,0.000);
    SpinerValue=(String)intent.getStringExtra(“SPINNERVALUE”);
    搜索地点=新纬度(纬度、经度);
    myMap.moveCamera(CameraUpdateFactory.newLatLng(SearchPlace));
    myMap.addMarker(新的MarkerOptions().position(SearchPlace));//.title(PlaceName));
    drawImageOverMap();
    }
    公共无效drawImageOverMap(){
    myMap.animateCamera(CameraUpdateFactory.zoomTo(zoomValue));
    //image=BitmapDescriptorFactory.fromResource(R.drawable.omnistar\g);
    if(SpinerValue.equalsIgnoreCase(“TEC”)){
    //中心点
    位图=(位图)BitmapFactory.decodeResource(this.getResources(),R.drawable.omnistar\u-two);
    BitmapFactory.Options o2=新的BitmapFactory.Options();
    o2.inSampleSize=4;
    image=BitmapDescriptorFactory.fromBitmap(位图);
    纬度边界=新纬度边界(西南、东北);
    mGroundOverlay=myMap.addGroundOverlay(新的GroundOverlayOptions()
    .图像(图像)
    //.透明度(0.4f)
    //.锚(0,1)
    .positionFromBounds(bounds));
    }
    else if(SpinerValue.equalsIgnoreCase(“OmniSTARG2”)){
    位图=(位图)BitmapFactory.decodeResource(this.getResources(),R.drawable.omnistar\u g\u img);
    BitmapFactory.Options o2=新的BitmapFactory.Options();
    o2.inSampleSize=4;
    image=BitmapDescriptorFactory.fromBitmap(位图);
    纬度边界=新纬度边界(西南、东北);
    mGroundOverlay=myMap.addGroundOverlay(新的GroundOverlayOptions()
    .图像(图像)
    .透明度(0.4f)
    //.锚(0,1)
    .positionFromBounds(bounds));
    }
    else if(SpinerValue.equalsIgnoreCase(“OmniStarHP”)){
    位图=(位图)BitmapFactory.decodeResource(this.getResources(),R.drawable.omnistar\u hp\u two);
    BitmapFactory.Options o2=新的BitmapFactory.Options();
    o2.inSampleSize=4;
    image=BitmapDescriptorFactory.fromBitmap(位图);
    纬度边界=新纬度边界(西南、东北);
    经理