屏幕旋转时旋转地图标记?
Rotate a map marker when screen rotates?
使用 Google 地图 API v2 时,我无法在 Android 应用旋转中创建自定义标记。我想像在优步应用程序中那样显示旋转。我在 Marker 上设置了 flat 属性,但它没有帮助。以下是片段
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
你可以这样试试
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f).rotation(180));
您可以使用轴承设备或遵循此 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()
method from Location
对象获取轴承更新
if (mLastLocation.hasBearing()) {
marker.setRotation(mLocation.getBearing());
}
//if following the linked tutorial
// marker.setRotation((float) azimuth);
在使用时也知道 this。
使用 Google 地图 API v2 时,我无法在 Android 应用旋转中创建自定义标记。我想像在优步应用程序中那样显示旋转。我在 Marker 上设置了 flat 属性,但它没有帮助。以下是片段
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f));
你可以这样试试
Marker marker = map.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.vehicle_marker)).flat(true).anchor(0.5f,0.5f).rotation(180));
您可以使用轴承设备或遵循此 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()
method from Location
对象获取轴承更新
if (mLastLocation.hasBearing()) {
marker.setRotation(mLocation.getBearing());
}
//if following the linked tutorial
// marker.setRotation((float) azimuth);
在使用时也知道 this。