【问题标题】:GPS Based AR: Get x,y Coordinate for Lat and Long基于 GPS 的 AR:获取纬度和经度的 x,y 坐标
【发布时间】:2021-07-24 19:58:06
【问题描述】:

我正在尝试查找给定经度和纬度的 x 和 y 坐标。我想在我的应用程序中使用 x 和 y 坐标在 three.js 中显示多维数据集。我使用了以下公式:

public calcPosFromLatLonRad ( lat: number, lon: number, radius: number ) {
        var phi   = (90 -  lat) * (Math.PI / 180);
        var theta = (lon + 180) * (Math.PI / 180);
        const x = -(radius * Math.sin(phi) * Math.cos(theta));
        const z = (radius * Math.sin(phi) * Math.sin(theta));
        const y = (radius * Math.cos(phi));
        console.log('x Koordinate: ' + x + ' y Koordinate: ' + y + 'z Koordinate: ' + z);
        return [x, y, z];
    }

然后我尝试了:

const x1 = this.calcPosFromLatLonRad(52.387980, 9.719260, 100);
        const pos1x = x1[0];
        const pos1y = x1[1];
        const pos1z = x1[2];

cube2.position.set(pos1x, pos1y, pos1z);
camera.position.z = 5;
        scene.add( cube2);
const animate  = () => {
    requestAnimationFrame( animate );
    controls.update();
    renderer.render( scene, camera );
};

但我在显示器上看不到任何东西。我做错了什么?

【问题讨论】:

    标签: three.js


    【解决方案1】:

    您的相机没有看到立方体。试试camera.lookAt( pos1x, pos1y, pos1z )

    【讨论】:

    • 我的屏幕上有多个元素。我想映射 3 个元素,包括它们的 GPS 坐标。当我使用 DeviceOrientationController 移动 Smarphone 时,它​​们应该在正确的位置。根据您的建议,我的相机只会看到一个元素。我该如何解决这个问题?
    • 在这种情况下,请尝试将相机移得更远。而不是5 试试200
    • 我做到了,但这并没有解决我的问题。当我打开相机时,我的坐标系就像“某处”,我放置的对象都在这个坐标系中。我想试试 AR.js 的指令。它说我必须将我的原始 GPS 位置设置为世界原点。我该怎么做?
    猜你喜欢
    • 1970-01-01
    • 2020-07-04
    • 2011-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多