使用 Google Maps API v2 时,我无法在 Android 应用程序旋转中创建我的自定义标记。我想像在优步应用程序中那样显示旋转。我已经在 Marker 上设置了 flat 属性,但它没有帮助。以下是 fragment
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
最佳答案
您可以使用轴承设备或按照此 tutorial 进行操作.
创建一个非常适合轴承更新的标记。
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));
使用 getBearing()
获取轴承更新方法来自 Location
对象
if (mLastLocation.hasBearing()) {
marker.setRotation(mLocation.getBearing());
}
//if following the linked tutorial
// marker.setRotation((float) azimuth);
了解 this也在你使用它的时候。
关于android - 屏幕旋转时旋转 map 标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33912226/