【问题标题】:Change person icon on map using OsmDroid使用 OsmDroid 更改地图上的人物图标
【发布时间】:2020-07-06 17:18:24
【问题描述】:

我在活动中使用 Osmdroid 作为地图,但我无法更改黄色人的默认图标。目前我正在尝试,但地图上没有显示任何内容。

 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_truck);
 mLocationOverlay.setPersonIcon(bitmap);
 map.getOverlays().add(mLocationOverlay);

在控制台中出现。

E/OsmDroid: error dispatchDraw, probably in edit mode
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.isRecycled()' on a null object reference
    at android.graphics.BaseCanvas.throwIfCannotDraw(BaseCanvas.java:54)
    at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:226)
    at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:78)

【问题讨论】:

    标签: java android android-mapview android-bitmap osmdroid


    【解决方案1】:

    查看您是否遗漏了代码中的某些上下文: map.getOverlays().add(mLocationOverlay);

    这是一个例子:

           //My Location
           //note you have handle the permissions yourself, the overlay did not do it for you
           mLocationOverlay = new MyLocationNewOverlay(new GpsMyLocationProvider(context), mMapView);
           mLocationOverlay.enableMyLocation();
           Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_menu_compass);
           mLocationOverlay.setPersonIcon(bitmap);
           mMapView.getOverlays().add(this.mLocationOverlay);
    

    在哪里

    private MyLocationNewOverlay mLocationOverlay;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多