【问题标题】:OSM - Show current location with custom iconOSM - 使用自定义图标显示当前位置
【发布时间】:2017-11-03 10:09:36
【问题描述】:

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

【问题讨论】:

  • 我问的是 OSM 而不是谷歌地图

标签: android openstreetmap osmdroid


【解决方案1】:

使用默认人物图标:

MyLocationNewOverlay myLocationoverlay = new MyLocationNewOverlay(mapView);
myLocationoverlay.enableFollowLocation();
myLocationoverlay.enableMyLocation();
mapView.getOverlays().add(myLocationoverlay);

带有自定义图标:

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

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

compile 'org.osmdroid:osmdroid-android:5.6.5'

【讨论】:

  • 很高兴为您提供帮助:)
  • 在哪里添加 currentIcon 变量?
  • 你应该最终将你的图标设置为人形图标myLocationoverlay.setPersonIcon( currentIcon ); 或方向箭头:myLocationoverlay.setDirectionArrow( personIcon, currentIcon );
  • 可能需要这个来加载一个drawable:stackoverflow.com/a/10600736/4421627
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-13
相关资源
最近更新 更多