首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在处理CameraPostion、CameraPostion.Builder时,正确的单位是什么?

在处理CameraPostion、CameraPostion.Builder时,正确的单位是什么?
EN

Stack Overflow用户
提问于 2016-06-22 23:26:34
回答 1查看 219关注 0票数 1

从文档中看,CameraPosition似乎应该对其承载成员使用度。然而,它的构建器类将传入的度数转换为弧度。

代码语言:javascript
复制
/**
 * 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的构造函数。看起来,由于构造者期望的是度,所以构造者应该以度为单位来保持方向角,或者如果以弧度为单位,则将其转换为度。

代码语言:javascript
复制
/**
 * 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;
EN

回答 1

Stack Overflow用户

发布于 2016-06-23 03:06:08

默认单位为degrees

正如您所提到的,构建器将度数转换为弧度。除非生成器使用isRadiant并将其设置为true,否则弧度始终作为double保留。看起来isRadiant是在Mapbox、Android SDK3.x和4.0.0之间引入的。

代码语言:javascript
复制
if (isRadiant) {
    this.bearing = bearing;
} else {
    // converting degrees to radiant
    this.bearing = (float) (-bearing * MathConstants.DEG2RAD);
}

构建器执行算术提升。在内部,方向角显然是弧度,但开发人员输入的是degrees

从文档中

  • @参数相机指向的方向,从北顺时针方向。该值将被标准化为0度(含)和360度(不含)。

Mapbox Android SDK4.0中的示例显式设置了isRadiant(false) -

代码语言:javascript
复制
                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);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37972357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档