Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.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_Map_Loading - Fatal编程技术网

Android 加载地图问题

Android 加载地图问题,android,map,loading,Android,Map,Loading,我已经从地图视图中捕获了我当前位置的屏幕截图,并将其导入到我的应用程序frm sd卡。我使用地图视图集成了地图。因此,我的应用程序运行,当地图加载时,一些方形框出现在我的地图中。在捕获图像后。当打开图像时,CRSSE出现。为什么会这样我的示例屏幕截图和代码如下所述 ![public void onClick(View v) { getMapImage(); saveMapImage(); }

我已经从地图视图中捕获了我当前位置的屏幕截图,并将其导入到我的应用程序frm sd卡。我使用地图视图集成了地图。因此,我的应用程序运行,当地图加载时,一些方形框出现在我的地图中。在捕获图像后。当打开图像时,CRSSE出现。为什么会这样我的示例屏幕截图和代码如下所述

            ![public void onClick(View v) {
            getMapImage();
            saveMapImage();

            }
        });

        // enable Street view by default
        mapView.setStreetView(true);

        // enable to show Satellite view
        // mapView.setSatellite(true);

        // enable to show Traffic on map
        // mapView.setTraffic(true);
        mapView.setBuiltInZoomControls(true);

        mapController = mapView.getController();
        mapController.setZoom(16); 
    }
    private Bitmap getMapImage() {  
        /* Position map for output */  
        MapController mc = mapView.getController();  
//        mc.setCenter(SOME_POINT);  
        mc.setZoom(16);  

        /* Capture drawing cache as bitmap */  
        mapView.setDrawingCacheEnabled(true);  
        Bitmap bmp = Bitmap.createBitmap(mapView.getDrawingCache());  
        mapView.setDrawingCacheEnabled(false);  

        return bmp;  
    }  

    private void saveMapImage() {  
        String filename = "foo.png";  
        File f = new File("/sdcard/", filename);  
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(f);
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }  

        Bitmap bmp = getMapImage();  

        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);  

        try {
            out.close();
        } catch (IOException e) {

            e.printStackTrace();
        }  
    }  
    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    private class GPSLocationListener implements LocationListener 
    {
        @Override
        public void onLocationChanged(Location location) {
            if (location != null) {
                GeoPoint point = new GeoPoint(
                        (int) (location.getLatitude() * 1E6), 
                        (int) (location.getLongitude() * 1E6));

                /* Toast.makeText(getBaseContext(), 
                        "Latitude: " + location.getLatitude() + 
                        " Longitude: " + location.getLongitude(), 
                        Toast.LENGTH_SHORT).show();*/

                mapController.animateTo(point);
                mapController.setZoom(16);

                // add marker
                MapOverlay mapOverlay = new MapOverlay();
                mapOverlay.setPointToDraw(point);
                List<Overlay> listOfOverlays = mapView.getOverlays();
                listOfOverlays.clear();
                listOfOverlays.add(mapOverlay);

                String address = ConvertPointToLocation(point);
                Toast.makeText(getBaseContext(), address, Toast.LENGTH_SHORT).show();

                mapView.invalidate();
            }
        }

        public String ConvertPointToLocation(GeoPoint point) {   
            String address = "";
            Geocoder geoCoder = new Geocoder(
                    getBaseContext(), Locale.getDefault());
            try {
                List<Address> addresses = geoCoder.getFromLocation(
                    point.getLatitudeE6()  / 1E6, 
                    point.getLongitudeE6() / 1E6, 1);

                if (addresses.size() > 0) {
                    for (int index = 0; index < addresses.get(0).getMaxAddressLineIndex(); index++)
                        address += addresses.get(0).getAddressLine(index) + " ";
                }
            }
            catch (IOException e) {                
                e.printStackTrace();
            }   

            return address;
        } 

        @Override
        public void onProviderDisabled(String provider) {
        }

        @Override
        public void onProviderEnabled(String provider) {
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    }

    class MapOverlay extends Overlay
    {
        private GeoPoint pointToDraw;

        public void setPointToDraw(GeoPoint point) {
            pointToDraw = point;
        }

        public GeoPoint getPointToDraw(
                ) {
            return pointToDraw;
        }

        @Override
        public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) {
            super.draw(canvas, mapView, shadow);                   

            // convert point to pixels
            Point screenPts = new Point();
            mapView.getProjection().toPixels(pointToDraw, screenPts);

            // add marker
            Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);
            canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 24, null); // 24 is the height of image        
            return true;
        }
    }][1] 
![public void onClick(视图五){
getMapImage();
saveMapImage();
}
});
//默认情况下启用街景
mapView.setStreetView(真);
//启用以显示卫星视图
//mapView.setSatellite(真);
//启用以在地图上显示流量
//mapView.setTraffic(true);
mapView.SetBuilTinZoomControl(真);
mapController=mapView.getController();
mapController.setZoom(16);
}
私有位图getMapImage(){
/*输出的位置映射*/
MapController mc=mapView.getController();
//mc.设置中心(某些点);
mc.setZoom(16);
/*将图形缓存捕获为位图*/
mapView.setDrawingCacheEnabled(true);
位图bmp=Bitmap.createBitmap(mapView.getDrawingCache());
mapView.setDrawingCacheEnabled(false);
返回bmp;
}  
私有void saveMapImage(){
字符串filename=“foo.png”;
文件f=新文件(“/sdcard/”,文件名);
FileOutputStream out=null;
试一试{
out=新文件输出流(f);
}catch(filenotfounde异常){
e、 printStackTrace();
}  
位图bmp=getMapImage();
bmp.compress(Bitmap.CompressFormat.PNG,100,out);
试一试{
out.close();
}捕获(IOE异常){
e、 printStackTrace();
}  
}  
@凌驾
受保护的布尔值isRouteDisplayed(){
返回false;
}
私有类GPSLocationListener实现LocationListener
{
@凌驾
已更改位置上的公共无效(位置){
如果(位置!=null){
地质点=新的地质点(
(int)(location.getLatitude()*1E6),
(int)(location.getLongitude()*1E6));
/*Toast.makeText(getBaseContext(),
“纬度:”+位置。getLatitude()+
“经度:”+location.getLongitude(),
吐司。长度(短)。show()*/
mapController.animateTo(点);
mapController.setZoom(16);
//添加标记
MapOverlay MapOverlay=新的MapOverlay();
mapOverlay.setPointToDraw(点);
List ListoForLays=mapView.getOverlays();
listOfOverlays.clear();
添加(映射覆盖);
字符串地址=转换点位置(点);
Toast.makeText(getBaseContext(),地址,Toast.LENGTH_SHORT).show();
mapView.invalidate();
}
}
公共字符串转换点定位(地理点){
字符串地址=”;
地理编码器地理编码器=新地理编码器(
getBaseContext(),Locale.getDefault();
试一试{
列表地址=geoCoder.getFromLocation(
point.getLatitudeE6()/1E6,
point.getLongitudeE6()/1E6,1);
如果(地址.size()>0){
for(int index=0;index
请尝试
mapView.setStreetView(错误),我曾经有过同样的问题,发现这是因为将街景设置为true