问题
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