Pergunta

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?

Foi útil?

Solução

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

Outras dicas

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

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)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top