使用 OsmDroid 更改地图上的人物图标
Change person icon on map using OsmDroid
我在 activity 中使用 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)
看看您是否遗漏了代码的某些上下文:
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;
我在 activity 中使用 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)
看看您是否遗漏了代码的某些上下文:
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;