添加罗盘旋转的MapView [英] Adding Compass to Rotate MapView
问题描述
我使用MapsDemo样品的code绘制,根据罗盘旋转的地图,但enableCompass工作不显示在MapView的指南针。我尝试添加该罗盘<一个href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html\" rel=\"nofollow\">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html.但是,当我将它添加到我的应用程序,箭头出现冻结。任何想法?
I'm using the code of MapsDemo Sample to draw a Map that rotates according to the compass, but enableCompass is not working to show the compass on MapView. I tried to add this compass http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html. But when I add it to my application, the arrow appears frozen. Any ideas?
推荐答案
请记住,它只会在实际硬件上运行。
Bear in mind that it will only work on actual hardware.
将这个行的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();
}
下面是一个示例项目,使罗盘 MyLocationOverlay
那肯定的作品,但你需要在自己的 Android的替代:apiKey
值
Here is a sample project that enables the compass on MyLocationOverlay
that definitely works, though you will need to substitute in your own android:apiKey
value.
这篇关于添加罗盘旋转的MapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!