如何在 Open Street Map 中启用指南针模式?
有没有方法或者我需要自己创建定向系统?
这就是我启用指南针的方式:
MapView oMap;
IMapController mapController;
.......
mapController = oMap.getController();
mapController.setZoom(zoom);
mapController.setCenter(new GeoPoint(latitude, longitude));
MyLocationNewOverlay oMapLocationOverlay = new
MyLocationNewOverlay(getApplicationContext(),oMap);
oMap.getOverlays().add(oMapLocationOverlay);
oMapLocationOverlay.enableFollowLocation();
oMapLocationOverlay.enableMyLocation();
CompassOverlay compassOverlay = new CompassOverlay(this, oMap);
compassOverlay.enableCompass();
oMap.getOverlays().add(compassOverlay);
要在地图上显示指南针,请使用enableCompass()
in MyLocationOverlay
。
启用方向传感器(指南针)更新并在地图上显示指南针。您可能需要从 Activity 的 Activity.onResume() 方法中调用 enableCompass() 来启用此叠加层的功能。请记住在您的 Activity 的 Activity.onPause() 方法中调用相应的 disableCompass() 以在后台关闭更新。
如果您还想旋转地图,还有一个osmdroid
实现该功能的分支:http ://code.google.com/p/osmdroid/source/browse/branches/rotation/OpenStreetMapViewer/src/org/osmdroid/MapActivity.java ?r=914
您只需要传递上下文和地图视图实例
CompassOverlay compassOverlay = new CompassOverlay(this, map);
compassOverlay.enableCompass();
map.getOverlays().add(compassOverlay);
创建指南针覆盖,启用然后将其添加到地图覆盖以显示
由于问题不清楚,我会给你我“认为”你所要求的,这是屏幕上的指南针。
CompassOverlay mCompassOverlay = new CompassOverlay(getContext(),
new InternalCompassOrientationProvider(getContext()),
mMapView);
mCompassOverlay.enableCompass();
mMapView.getOverlays().add(this.mCompassOverlay);