屏幕旋转时是否旋转地图标记?

Anu*_*ugh 1 android google-maps rotation google-maps-markers

使用Google Maps API v2时,无法在Android App Rotate中进行自定义标记。我想展示Uber App中发生的旋转。我已经在Marker上设置了flat属性,但这没有帮助。以下是摘要

Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
Run Code Online (Sandbox Code Playgroud)

Ano*_*p M 5

您可以使用带有轴承的设备来做到这一点,或按照本教程进行操作

创建一个非常适合方位更新的标记。

private Marker marker;

// Create this marker only once; probably in your onMapReady() method
marker = mGoogleMap.addMarker(new MarkerOptions()
        .position(new LatLng(myLatitude, myLongitude))
        .flat(true));
Run Code Online (Sandbox Code Playgroud)

使用对象的getBearing()方法获取方位更新Location

  if (mLastLocation.hasBearing()) {
     marker.setRotation(mLocation.getBearing());
    }
     //if following the linked tutorial
    // marker.setRotation((float) azimuth);
Run Code Online (Sandbox Code Playgroud)

使用时也要意识到一点。