I'm actually trying to show a map in an app, built with Android Studio. I use the Library "mapsforge" (https://github.com/mapsforge) At creating a map view instance I get an error.
I integrated the following libs:
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'
And in MainActivity:
import org.mapsforge.map.view.MapView;
My whole 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));
}
}
Throws:
MapView is abstract - cannot be instantiated.
Sry new in Java
Thanks in advance
To use the MapView in Android you need to add the Android implementation to your gradle dependencies:
see the integration guide from their repository: https://github.com/mapsforge/mapsforge/blob/master/docs/Integration.md