Adding Compass to Rotate MapView

后端 未结 1 753
抹茶落季
抹茶落季 2021-01-27 06:04

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

相关标签:
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.

    0 讨论(0)
提交回复
热议问题