从文档中看,CameraPosition似乎应该对其承载成员使用度。然而,它的构建器类将传入的度数转换为弧度。
/**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
*
* @param bearing Bearing
* @return Builder
*/
public Builder bearing(double bearing) {
if (isRadiant) {
this.bearing = bearing;
} else {
// converting degrees to radiant
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
}
return this;
}下面是CameraPosition的构造函数。看起来,由于构造者期望的是度,所以构造者应该以度为单位来保持方向角,或者如果以弧度为单位,则将其转换为度。
/**
* Constructs a CameraPosition.
*
* @param target The target location to align with the center of the screen.
* @param zoom Zoom level at target. See zoom(float) for details of restrictions.
* @param tilt The camera angle, in degrees, from the nadir (directly down). See tilt(float) for details of restrictions.
* @param bearing Direction that the camera is pointing in, in degrees clockwise from north. This value will be normalized to be within 0 degrees inclusive and 360 degrees exclusive.
* @throws NullPointerException if target is null
* @throws IllegalArgumentException if tilt is outside the range of 0 to 90 degrees inclusive.
*/
CameraPosition(LatLng target, double zoom, double tilt, double bearing) {
this.target = target;
this.bearing = bearing;
this.tilt = tilt;
this.zoom = zoom;发布于 2016-06-23 03:06:08
默认单位为degrees。
正如您所提到的,构建器将度数转换为弧度。除非生成器使用isRadiant并将其设置为true,否则弧度始终作为double保留。看起来isRadiant是在Mapbox、Android SDK3.x和4.0.0之间引入的。
if (isRadiant) {
this.bearing = bearing;
} else {
// converting degrees to radiant
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
}构建器执行算术提升。在内部,方向角显然是弧度,但开发人员输入的是degrees。
从文档中
Mapbox Android SDK4.0中的示例显式设置了isRadiant(false) -
CameraPosition position = new CameraPosition.Builder()
.target(new LatLng(32.9, -116.9))
.zoom(17) // Sets the zoom
.isRadiant(false)
.bearing(180) // Rotate the camera 180 degrees
.tilt(30) // Set the camera tilt
.build(); // Creates a CameraPosition from the builder
mapboxMap.animateCamera(CameraUpdateFactory
.newCameraPosition(position), 7000);https://stackoverflow.com/questions/37972357
复制相似问题