从文档来看,似乎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;
答案 0 :(得分:2)
默认单位为degrees
。
正如您所提到的,构建器将度数转换为弧度。除非Builder使用isRadiant
并将其设置为true,否则将保持不变,然后将弧度保留为double。看起来在Mapbox Android SDK 3.x和4.0.0之间引入了isRadiant
。
if (isRadiant) {
this.bearing = bearing;
} else {
// converting degrees to radiant
this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
}
构建器执行算术提升。在内部,轴承显然是弧度,但开发人员输入为degrees
。
来自文档
- @param bearing相机指向的方向,以北为顺时针方向的度数。该值将标准化为0 包含度和360度独家。
Mapbox Android SDK 4.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);