【问题标题】:Rotate a map marker when screen rotates?屏幕旋转时旋转地图标记?
【发布时间】:2015-12-01 11:57:03
【问题描述】:
使用 Google Maps API v2 时,我无法在 Android App Rotate 中制作自定义标记。我想像在 Uber 应用程序中那样显示旋转。我已经在 Marker 上设置了 flat 属性,但它没有帮助。以下是sn -p
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
【问题讨论】:
标签:
android
google-maps
rotation
google-maps-markers
【解决方案1】:
您可以使用设备轴承或关注此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));
使用Location对象中的getBearing()方法获取方位更新
if (mLastLocation.hasBearing()) {
marker.setRotation(mLocation.getBearing());
}
//if following the linked tutorial
// marker.setRotation((float) azimuth);
在使用this 时也要注意它。
【解决方案2】:
你可以这样试试
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f).rotation(180));