Jan-Terje Sørensen
Jan-Terje Sørensen

Reputation: 14698

How to display the current position pointer in osmdroid?

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?

Upvotes: 2

Views: 9831

Answers (3)

Farshid roohi
Farshid roohi

Reputation: 768

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)

Upvotes: 0

Ifor
Ifor

Reputation: 2835

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

Upvotes: 4

Amit
Amit

Reputation: 123

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

Upvotes: 0

Related Questions