Reputation: 207
I'm writing an android app that uses osmdroid. Right now the map displays and my current location marker (the triangle) rotates on top of the map. Instead of this I would like the MAP to rotate and the current location triangle marker to be locked in one position like a typical car GPS. This is my current code.
public class MainActivity extends Activity {
protected static final String PROVIDER_NAME = LocationManager.GPS_PROVIDER;
public static final GeoPoint SCHOOL = new GeoPoint(33.989820, -81.029123);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setClickable(true);
mapView.setBuiltInZoomControls(true);
mapView.setMultiTouchControls(true);
mapView.setUseDataConnection(true);
//mapView.setMapOrientation(0);
mapView.setTileSource(TileSourceFactory.MAPQUESTOSM);
MyLocationNewOverlay myLocationOverlay = new MyLocationNewOverlay(getApplicationContext(), mapView);
myLocationOverlay.enableMyLocation();
myLocationOverlay.enableFollowLocation();
mapView.getOverlays().add(myLocationOverlay);
IMapController mapViewController = mapView.getController();
mapViewController.setZoom(16);
}
}
Any ideas on what needs to be fixed/added?
Upvotes: 0
Views: 993
Reputation: 658
Use this instead default MyLocationNewOverlay:
class LocationOverlay(map: MapView) : MyLocationNewOverlay(map) {
override fun drawMyLocation(canvas: Canvas?, pj: Projection?, lastFix: Location?) {
if (this.isFollowLocationEnabled) rotateMap(lastFix)
super.drawMyLocation(canvas, pj, lastFix)
}
private fun rotateMap(lastFix: Location?) {
lastFix?.let {
if (it.speed > 0.2) {
mMapView.mapOrientation = -it.bearing
}
}
}
}
Upvotes: 1
Reputation: 3450
The behaviour you want is implemented in OSMNavigator MapActivity, using: DirectedLocationOverlay, and LocationListener. Have a look.
Upvotes: 0