其他分享
首页 > 其他分享> > android – OsmDroid显示当前的LocationIcon无法正常工作

android – OsmDroid显示当前的LocationIcon无法正常工作

作者:互联网

我在我的Android应用程序中使用OSMDroid.一切正常,但我无法显示图标以显示我当前的位置.
遵循我的准则:

openMapView = (org.osmdroid.views.MapView) v.findViewById(R.id.openmapview);
openMapView.setClickable(true);

openMapView.setMultiTouchControls(true);
final float scale = getResources().getDisplayMetrics().density;
final int newScale = (int) (256 * scale);
String[] OSMSource = new String[2];
OSMSource[0] = "http://a.tile.openstreetmap.org/";
OSMSource[1] = "http://b.tile.openstreetmap.org/";
XYTileSource MapSource = new XYTileSource(
    "OSM",
    null,
    1,
    18,
    newScale,
    ".png",
    OSMSource
);
openMapView.setTileSource(MapSource);
mapController = (MapController) openMapView.getController();
mapController.setZoom(14);

// My Location Overlay
myLocationoverlay = new MyLocationOverlay(getActivity(), openMapView);
myLocationoverlay.enableMyLocation(); // not on by default
myLocationoverlay.enableCompass();
myLocationoverlay.disableFollowLocation();
myLocationoverlay.setDrawAccuracyEnabled(true);

myLocationoverlay.runOnFirstFix(new Runnable() {
    public void run() {
        mapController.animateTo(myLocationoverlay.getMyLocation());
    }
});

任何人都可以给我一个想法,我要去哪里以及我的代码应该改变什么.

解决方法:

要启用MyLocationOverlay,您需要调用:

myLocationoverlay.enableMyLocation();
mMapView.getOverlays().add(mMyLocationNewOverlay);

另外从您的代码中删除此行:

myLocationoverlay.disableFollowLocation();

标签:android,icons,osmdroid,currentlocation
来源: https://codeday.me/bug/20190728/1558943.html