我尝试用mapsforge开始我的第一个项目。所以我这样做了,改变了app / build.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'org.mapsforge:mapsforge-map-android:0.8.0'
compile 'com.caverock:androidsvg:1.2.2-beta-1'
compile('org.mapsforge:mapsforge-map-android-extras:0.8.0') {
transitive = false
}
}
然后,我从这里获取代码:Code Example App。 这是我的MainActivity
package kn.com.ff_map;
import android.os.Bundle;
import android.app.Activity;
import android.os.Environment;
import org.mapsforge.core.model.LatLong;
import org.mapsforge.map.android.graphics.AndroidGraphicFactory;
import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.android.view.MapView;
import org.mapsforge.map.datastore.MapDataStore;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.layer.renderer.TileRendererLayer;
import org.mapsforge.map.reader.MapFile;
import org.mapsforge.map.rendertheme.InternalRenderTheme;
import java.io.File;
public class MainActivity extends Activity {
// name of the map file in the external storage
private static final String MAP_FILE = "berlin.map";
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidGraphicFactory.createInstance(this.getApplication());
this.mapView = new MapView(this);
setContentView(this.mapView);
this.mapView.setClickable(true);
this.mapView.getMapScaleBar().setVisible(true);
this.mapView.setBuiltInZoomControls(true);
this.mapView.setZoomLevelMin((byte) 10);
this.mapView.setZoomLevelMax((byte) 20);
// create a tile cache of suitable size
TileCache tileCache = AndroidUtil.createTileCache(this, "mapcache",
mapView.getModel().displayModel.getTileSize(), 1f,
this.mapView.getModel().frameBufferModel.getOverdrawFactor());
// tile renderer layer using internal render theme
MapDataStore mapDataStore = new MapFile(new File(Environment.getExternalStorageDirectory(), MAP_FILE));
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
this.mapView.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);
// only once a layer is associated with a mapView the rendering starts
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);
this.mapView.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.setZoomLevel((byte) 12);
}
@Override
protected void onDestroy() {
this.mapView.destroyAll();
AndroidGraphicFactory.clearResourceMemoryCache();
super.onDestroy();
}
}
我总是得到错误,
错误:(16,37)错误:找不到符号类InternalRenderTheme
错误:(50,45)错误:找不到符号变量InternalRenderTheme
所以这是我第一次尝试在我的项目中集成lib。我只这样做,我没有下载任何东西或从回购中复制任何东西。我必须下载mapforge或这个错误意味着什么?
答案 0 :(得分:1)
我的决定是添加到app的build.gragle
compile 'org.mapsforge:mapsforge-themes:0.8.0'