我正在使用MapsDemo Sample的代码绘制一个根据指南针旋转的地图,但是enableCompass无法在MapView上显示指南针。我试图添加这个指南针http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html。但是当我将它添加到我的应用程序时,箭头显示为冻结。有什么想法吗?
答案 0 :(得分:0)
请记住,它只适用于实际的硬件。
将此行放在onCreate
:
MyLocationOverlay me = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(me);
然后添加:
@Override
protected void onResume() {
super.onResume();
me.enableCompass();
}
@Override
public void onPause() {
super.onPause();
me.disableCompass();
}
这是一个sample project,可以使MyLocationOverlay
上的指南针确实有效,但您需要替换自己的android:apiKey
值。