我在路线上有几个站点,我想用自定义图标显示它们。使用默认的 osmdroid 图标时,一切都像魅力一样。但是当我将它们从可绘制图像更改为图像时,标记会显示在路线上方(参见图像)。
Marker marker = new Marker(mapView);
marker.setPosition(new GeoPoint(info.getLat(), info.getLon()));
marker.setAnchor(ANCHOR_CENTER, ANCHOR_BOTTOM);
marker.setTitle(info.getName());
Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.bus, null);
Bitmap bitmap = ((BitmapDrawable) d).getBitmap();
Drawable dr = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmap, (int) (48.0f * getResources().getDisplayMetrics().density), (int) (48.0f * getResources().getDisplayMetrics().density), true));
marker.setIcon(dr);
mapView.getOverlays().add(marker);
mapView.invalidate();
Run Code Online (Sandbox Code Playgroud)
我使用osmbonuspack:6.6.0和osmdroid-android:6.1.0和Android 9 (API 28)。我已经尝试按照OSMDroid - 在 Android API 28 上缩小时默认标记移动android:hardwareAccelerated="false"中所述进行设置 ,但它不起作用。还有其他解决办法吗?setAnchor(ANCHOR_CENTER,ANCHOR_CENTER)