android maps auto-rotate

后端 未结 5 1866
自闭症患者
自闭症患者 2020-12-12 19:45

If you open the Google maps app, there is a button on the top right of the screen that you can press to center the map on your current location. The button\'s icon then chan

5条回答
  •  心在旅途
    2020-12-12 20:21

    The new Location class already gives you the bearing automatically, why not use it?

    Sample code:

    private void updateCameraBearing(GoogleMap googleMap, Location myLoc) {
        if ( googleMap == null) return;
        CameraPosition camPos = CameraPosition
                .builder(googleMap.getCameraPosition())
                .bearing(myLoc.getBearing())
                 // if you want to stay centered - then add the line below
                .target(new LatLng(myLoc.getLatitude(), myLoc.getLongitude()))
                .build();
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(camPos));
    }
    

提交回复
热议问题