OSM - 使用自定义图标显示当前位置

And*_*Guy 2 android openstreetmap osmdroid

谁能告诉我如何使用自定义图标在 OSM 地图上显示我的当前位置?

小智 7

使用默认人物图标:

MyLocationNewOverlay myLocationoverlay = new MyLocationNewOverlay(mapView);
myLocationoverlay.enableFollowLocation();
myLocationoverlay.enableMyLocation();
mapView.getOverlays().add(myLocationoverlay);
Run Code Online (Sandbox Code Playgroud)

使用自定义图标:

MyLocationNewOverlay myLocationoverlay = new MyLocationNewOverlay(mapView);
myLocationoverlay.enableFollowLocation();
Drawable currentDraw = ResourcesCompat.getDrawable(getResources(), R.mipmap.ic_launcher, null);
Bitmap currentIcon = null;
if (currentDraw != null) {
    currentIcon = ((BitmapDrawable) currentDraw).getBitmap();
}
myLocationoverlay.setPersonIcon(currentIcon);
myLocationoverlay.enableMyLocation();
mapView.getOverlays().add(myLocationoverlay);
Run Code Online (Sandbox Code Playgroud)

我正在使用更新的 OSM 依赖项

compile 'org.osmdroid:osmdroid-android:5.6.5'
Run Code Online (Sandbox Code Playgroud)

  • 您最终应该将您的图标设置为人物图标 `myLocationoverlay.setPersonIcon( currentIcon);` 或方向箭头:`myLocationoverlay.setDirectionArrow( personIcon, currentIcon );` (3认同)