How to display the current position pointer in osmdroid?

点点圈 提交于 2019-12-06 12:10:37

问题


I would like to display the current position pointer using osmdroid.

getController().setCenter(new GeoPoint(location));

This code does not display the pointer. So is there anything built in for osmdroid as it is for google maps?


回答1:


You need to add a MyLocationOverlay somthing like the following.

        mMyLocationOverlay = new MyLocationOverlay(this, mOsmv,
                mResourceProxy);
        mMyLocationOverlay.disableMyLocation(); // not on by default
        mMyLocationOverlay.disableCompass();
        mMyLocationOverlay.disableFollowLocation();
        mMyLocationOverlay.setDrawAccuracyEnabled(true);
        mMyLocationOverlay.runOnFirstFix(new Runnable() {
            public void run() {
                mOsmvController.animateTo(mMyLocationOverlay
                        .getMyLocation());
            }
        });
        mOsmOverlays.add(mMyLocationOverlay);



回答2:


SetCenter will only set the map position to particular location. It won't add any pointer to the center. You either use mapview.addView or addoverlay of mapView. Osmdroid provides almost same functionality as that of MapView




回答3:


kotlin code :

 val mMyLocationOverlay = MyLocationNewOverlay(GpsMyLocationProvider(this), myMapView)
            val mapController = mapView.controller
            mMyLocationOverlay.disableMyLocation()
            mMyLocationOverlay.disableFollowLocation()
            mMyLocationOverlay.isDrawAccuracyEnabled = true
            mMyLocationOverlay.runOnFirstFix {
                runOnUiThread {
                    mapController.animateTo(mMyLocationOverlay.myLocation)
                    mapController.setZoom(18)
                }
            }
    mapView.overlays.add(mMyLocationOverlay)


来源:https://stackoverflow.com/questions/8804788/how-to-display-the-current-position-pointer-in-osmdroid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!