Adding Compass to Rotate MapView

自作多情 提交于 2019-12-12 02:57:55

问题


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?


回答1:


Bear in mind that it will only work on actual hardware.

Put this line in onCreate:

    MyLocationOverlay me = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(me);

Then add this:

@Override
protected void onResume() {
    super.onResume();
    me.enableCompass();
}

@Override
public void onPause() {
    super.onPause();
    me.disableCompass();
}

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.



来源:https://stackoverflow.com/questions/10177426/adding-compass-to-rotate-mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!