问题
I recently started to use OSMDroid, but I struggle to get a default marker at a specific Geopoint on Android API 28. I followed the tutorial from the OSMDroid's Github and wrote a code like this:
//Making a Mapbox TileSource
MapBoxTileSource mbTest = new MapBoxTileSource("mapbox.streets", ACCESS_TOKEN);
map = (MapView) findViewById(R.id.map);
map.setTileSource(mbTest);
//Setting up map
map.setVisibility(View.VISIBLE);
map.setMultiTouchControls(true);
map.getController().setCenter(new GeoPoint(latitude,longitude));
map.getController().setZoom(14d);
//Create a marker where the user is
Marker positionMarker = new Marker(map);
positionMarker.setDefaultIcon();
positionMarker.setPosition(new GeoPoint(latitude, longitude));
map.getOverlays().add(positionMarker);
And I have the following result when i test my app (i draw a polygon using OSMDroid and it seems to work fine):
I tested the same app on an Android API 22 device and the marker worked fine, being and staying at the right location while scaling with the zoom level.
Is there any way to fix or improve my code to make the marker work on API 28 ?
回答1:
I read some documentation about OSMDroid, and it seems that hardware acceleration is not always stable with it. I tried to deactivate it and it worked.
So if your marker seems to not be at the right location and moving when you zoom in or out, just deactivate hardware acceleration for this activity in the Android Manifest:
<activity
android:name=".MapActivity"
android:hardwareAccelerated="false"/>
Edit: I've worked further with OSMDroid and this issue does not occur when I use custom icons for my markers, so it shouldn't be a big concern for your apps.
来源:https://stackoverflow.com/questions/54811451/osmdroid-default-marker-moving-when-zooming-out-on-android-api-28