【发布时间】:2019-09-02 19:22:51
【问题描述】:
我实际上是在尝试在使用 Android Studio 构建的应用中显示地图。 我使用图书馆“mapsforge”(https://github.com/mapsforge) 在创建地图视图实例时出现错误。
我集成了以下库:
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'org.mapsforge:mapsforge-core:[0.11.0]'
implementation 'org.mapsforge:mapsforge-map:[0.11.0]'
implementation 'org.mapsforge:mapsforge-map-reader:[0.11.0]'
implementation 'org.mapsforge:mapsforge-themes:[0.11.0]'
implementation 'net.sf.kxml:kxml2:2.3.0'
在 MainActivity 中:
import org.mapsforge.map.view.MapView;
我的整个 OnCreate:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AndroidGraphicFactory.createInstance(getApplication());
mapView = new MapView(this);
mapView.setClickable(true);
mapView.getMapScaleBar().setVisible(false);
mapView.setBuiltInZoomControls(false);
mapView.setZoomLevelMin((byte) 2);
mapView.setZoomLevelMax((byte) 10);
mapView.setZoomLevel((byte) 2);
mapView.getModel().displayModel.setBackgroundColor(ContextCompat.getColor(t his, R.color.mapBackground));
}
}
投掷:
MapView 是抽象的 - 无法实例化。
Java 中的新人
提前致谢
【问题讨论】:
-
他们在示例代码中使用了不同的导入:
import org.mapsforge.map.android.view.MapView; -
感谢您的帮助!但它只是说:“未使用的导入语句”和“android”是红色标记的。
标签: java android android-studio mapsforge