OSMDroid - Default marker moving when zooming out on Android API 28

旧街凉风 提交于 2020-04-11 12:42:12

问题


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):

The marker should be on the corner of the polygon

The marker is moving when zooming out

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!