gpt4 book ai didi

android - 地理坐标(经度、纬度)到米 (x,y)

转载 作者:行者123 更新时间:2023-11-29 01:03:50 25 4
gpt4 key购买 nike

我的工作坐标系如下图所示:

enter image description here

x 和 y 以米为单位。我只对正 x,y 感兴趣。我想将 (x,y) 转换为 (lat,lon),反之亦然。

我认为这很简单,我没有发现下面的解决方案有问题。但我没有得到非常正确的结果。

我的解决方案:

如下图所示,我将纬度和经度视为 2 个圆的角度:

enter image description here

<强>1。 (x,y) 到 (lat,lon)

我在两者上都应用了弧长公式 ( here ),如下所示; x 和 y enter image description here enter image description here

因此,我的功能是:

private static double calculateLat(float x) {
int earthRadius = 6371000;
return REF_LOC.getLatitude() + x*360/(2*PI*earthRadius);
}

private static double calculateLong(float y) {
int earthRadius = 6371000;
return REF_LOC.getLongitude() + y*360/(2*PI*earthRadius);
}

REF_LOC 是 (x,y) 为 (0,0) 的引用地理位置。它可以是地球上的任何一点。

<强>2。 (lat,lon) 到 (x,y)

为此我只是使用这个:

int calculateX(double longitude){
Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
REF_LOC.getLatitude(), lonDeg, results);
return results[0];
}

int calculateY(double latitude){
Location.distanceBetween(REF_LOC.getLatitude(), REF_LOC.getLongitude(),
latDeg, REF_LOC.getLongitude(), results);
return results[0];
}

但我得到的结果不一致。首先,我使用解决方案 1 并将一些值 (x,y) 转换为 (lat,long)。但是当我使用解决方案 2 将相同的 (lat,long) 返回到 (x,y) 时,我得到 x 大约 2 米的差异和 y 的 10 米差异。谁能帮我找出问题所在?

最佳答案

提到我对球形与椭圆形计算的评论,另一种查看球形与椭圆形距离的距离计算差异的方法是使用 2 个可用的实用程序:

// For REF_LOC = (70, 20)

// Compute a lat/lng due east of a REF_LOC and compute distance using both
// available methods.

LatLng P = SphericalUtil.computeOffsetOrigin(REF_LOC, 20000, 90.0);

// And then compute a distance
d = SphericalUtil.computeDistanceBetween(REF_LOC, P);
Location.distanceBetween(REF_LOC.latitude, REF_LOC.longitude, P.latitude, P.longitude, results);

// d = 20000.000000000036
// results[0] = 20081.818


// and for a REF_LOC = (0, 20)
// d = 20000.000000000127
// results[0] = 20022.377

同样有趣的是 SphericalUtil.computeOffsetOrigin() 会产生错误纬度从赤道到极点增加,使其不对称。然而,由此产生的距离基本上是精确的。

我建议使用 SphericalUtil.computeOffsetOrigin 来计算 X/Y 中断将其转换为纬度和经度偏移量。

最后展示 SphericalUtil 解决方案:

// Start with some arbitrary x/y relative to REF_LOC
double Rx = 125.0;
double Ry = 73.0;

// Compute a lat/lon from REF_LOC to the point
LatLng Rll = new LatLng(SphericalUtil.computeOffsetOrigin(REF_LOC, Ry, 180).latitude,
SphericalUtil.computeOffsetOrigin(REF_LOC, Rx, 270).longitude);

// And recompute the x/y components of the lat/lon

double Rxx = SphericalUtil.computeDistanceBetween(REF_LOC, new LatLng(REF_LOC.latitude, Rll.longitude));
double Ryy = SphericalUtil.computeDistanceBetween(REF_LOC, new LatLng(Rll.latitude, REF_LOC.longitude));

导致:

Rx/Ry   = (125.0, 73.0)
Rxx/Ryy = (125.00000004545973, 73.00000000137051)

我认为是可接受的错误。

所以最后的问题是 - x/y 真正代表什么?

请引用这两个实用程序的源以获取更多信息:

Location

SphericalUtil

关于android - 地理坐标(经度、纬度)到米 (x,y),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49094949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com