Android Can';t使用google maps v.2旋转标记
目标是使标记朝下一个坐标点旋转。以下是获取角度的方法:Android Can';t使用google maps v.2旋转标记,android,google-maps,Android,Google Maps,目标是使标记朝下一个坐标点旋转。以下是获取角度的方法: private double computeAngleBetween(LatLng from, LatLng to) { double fromLat = from.latitude; double fromLng = from.longitude; double toLat = to.latitude; double toLng = to.longitude; double dLat = fromL
private double computeAngleBetween(LatLng from, LatLng to) {
double fromLat = from.latitude;
double fromLng = from.longitude;
double toLat = to.latitude;
double toLng = to.longitude;
double dLat = fromLat - toLat;
double dLng = fromLng - toLng;
return 2 * asin(sqrt(pow(sin(dLat / 2), 2) +
cos(fromLat) * cos(toLat) * pow(sin(dLng / 2), 2)));
}
下面是代码,我在其中创建了一个标记:
@Override
public void onMapReady(GoogleMap googleMap) {
//Unnecessary code is deleted
float bearing = (float)computeAngleBetween(theRoute.get(0),theRoute.get(1));
Marker theAirplane = gMap.addMarker(new MarkerOptions()
.position(start)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.airplane))
.flat(true)
.anchor(0.5f, 0.5f)
.rotation(bearing)
.draggable(true));
theAirplane.setRotation(bearing);
movePlane(theAirplane, theRoute.size()-1);
}
所以,我不知道问题出在哪里。似乎一切正常,但没有任何效果,您能帮我吗?您可以使用“设置旋转(浮动旋转)”来设置标记的旋转。旋转轴垂直于标记。旋转0对应于标记的默认位置
确保您的项目已连接最新的Play Services SDK。您需要从SDK管理器下载r12,然后将该库项目附加到您的项目中
下面是一个示例项目,演示如何使用“setRotation”:
这里是我找到答案的地方:试着把它转换成度,比如
Math.toDegrees(弧度)