我使用MOBAC(Osmdroid zip格式,OpenStreetMap MapQuest源代碼)創建了一個地圖。 現在我有我的android項目的資產文件夾中的這個zip文件(該文件的名稱是prova.zip),我需要在我的手機(內部存儲器)內複製到/ sdcard/osmdroid/ 我發現了一些類網絡,但他們不工作,也許我做錯了什麼。如何將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();
}
}
我試圖實現這個代碼,但它不能在MOBAC工作
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卡或嵌入此壓縮瓷磚一般? – MaM
你還沒有解釋什麼不適合你。 – scai
不清楚你在問什麼 –