【发布时间】:2014-01-19 13:20:41
【问题描述】:
我使用 MOBAC(Osmdroid zip 格式,OpenStreetMap MapQuest 源)创建了一张地图。
现在我在我的 Android 项目的 assets 文件夹中有这个 ZIP 文件(文件名是 prova.zip),我需要在我的手机(内存)中复制到 /sdcard/osmdroid/。
我在网上找到了一些课程,但它们不起作用或者我做错了什么。
我该如何解决这个问题?
MainActivity.java
public class MainActivity extends Activity {
MyItemizedOverlay myItemizedOverlay = null;
MyLocationOverlay myLocationOverlay = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
IMapController mapController = mapView.getController();
mapController.setZoom(18);
ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(this);
mapView.getOverlays().add(myScaleBarOverlay);
GeoPoint startPoint = new GeoPoint(0, 0);
myLocationOverlay = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocationOverlay);
myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
mapView.getController().animateTo(myLocationOverlay.getMyLocation());
}
});
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableCompass();
myLocationOverlay.enableFollowLocation();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
myLocationOverlay.disableMyLocation();
myLocationOverlay.disableCompass();
myLocationOverlay.disableFollowLocation();
}
}
我试图实现这段代码,但它不起作用:
private void copyAssets() {
AssetManager assetManager = getAssets();
String[] files = null;
try {
files = assetManager.list("");
}
catch (IOException e) {
Log.e("tag", "Failed to get asset file list.", e);
}
for(String prova : files) {
InputStream in = null;
OutputStream out = null;
try {
in = assetManager.open(prova);
File outFile = new File(getExternalFilesDir(null) + "/sdcard/osmdroid/", prova);
out = new FileOutputStream(outFile);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
}
catch(IOException e) {
Log.e("tag", "Failed to copy asset file: " + prova, e);
}
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
}
【问题讨论】:
-
那么您的问题是从资产复制到 SD 卡还是嵌入此压缩图块?
-
你还没有解释到底什么不适合你。
-
不清楚你在问什么
-
我想将 zip 文件从资产复制到 sdcard。我需要一堂课来做到这一点,但我不知道该怎么做
标签: android openstreetmap osmdroid