Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 地理坐标(长、纬度)到米(x、y)_Android_Google Maps_Coordinates - Fatal编程技术网

Android 地理坐标(长、纬度)到米(x、y)

Android 地理坐标(长、纬度)到米(x、y),android,google-maps,coordinates,Android,Google Maps,Coordinates,我的工作坐标系如下所示: x和y以米为单位。我只对正x,y感兴趣。我想把(x,y)转换成(lat,lon),反之亦然 我认为这很简单,我认为下面的解决方案没有问题。但我没有得到非常正确的结果 我的解决方案: 如下图所示,我将纬度和经度视为两个圆圈的角度: 1。(x,y)到(lat,lon) 我将弧长公式()(如下所示)应用于这两种情况;x和y 因此,我的职能是: private static double calculateLat(float x) { int earthRadiu

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

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

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

我的解决方案:

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

1。(x,y)到(lat,lon)

我将弧长公式()(如下所示)应用于这两种情况;x和y

因此,我的职能是:

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。(横向,纵向)至(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)。但是,当我使用相同的(lat,long)返回到(x,y)使用解决方案2时,我得到x的大约2米差和y的10米差。有人能帮我找出这个问题吗?

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

// 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真正代表什么

有关更多信息,请参考这两个实用程序的源:


我估计差异的结果是,您的(1)正在建模球体,而(2)(使用Location.distanceBetween)正在建模椭球体,其中椭球体的轴定义为:
double a=6378137.0;//WGS84长轴和双b=6356752.3142;//WGS84半长轴
也可以查看错误大小的解释。这已经奏效了!虽然如果在您的解决方案中使用Location.distanceBetween()而不是SphereCalutil.ComputedDistancebetween(),它会给出错误的结果。可能是cz,它们使用不同的半径值。嗯,转换是一致的(前后),但我还没有在地面上测试它,看看它是否给出正确的结果。谢谢!我刚刚发现我必须反转角度(0->180和90->270)才能使它工作。是的,computeOffsetOrigin是“TO”,所以在球面解中,它应该是你为航向指示的,将点放在象限1中。代码更新-谢谢。