Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.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
Java 在安卓系统中,通过一定数量的米来抵消LatLng_Java_Android_Coordinates_Latitude Longitude_Coordinate Transformation - Fatal编程技术网

Java 在安卓系统中,通过一定数量的米来抵消LatLng

Java 在安卓系统中,通过一定数量的米来抵消LatLng,java,android,coordinates,latitude-longitude,coordinate-transformation,Java,Android,Coordinates,Latitude Longitude,Coordinate Transformation,我有一个LatLng对象,我想把它的坐标向东移动500米。我找不到一个内置的方法。我见过,但我的结果太不准确(约15%),无法实际使用。如何以米为单位精确转换 注意:我不是在寻找移动谷歌地图相机,我知道怎么做 我试过: static final double KILOMETERS_PER_DEGREE = 111.111; static LatLng offsetLongitude(LatLng initialCoords, float horizontalOffsetInMeters){

我有一个
LatLng
对象,我想把它的坐标向东移动500米。我找不到一个内置的方法。我见过,但我的结果太不准确(约15%),无法实际使用。如何以米为单位精确转换

注意:我不是在寻找移动谷歌地图相机,我知道怎么做

我试过:

static final double KILOMETERS_PER_DEGREE = 111.111;

static LatLng offsetLongitude(LatLng initialCoords, float horizontalOffsetInMeters){
    double degreeOffset = 1.0 / KILOMETERS_PER_DEGREE * horizontalOffsetInMeters / 1000.0;
    double longitudeOffset = Math.cos(initialCoords.latitude * Math.PI / 180.0) * degreeOffset;
    return new LatLng(initialCoords.latitude, initialCoords.longitude + longitudeOffset);
}

public static LatLngBounds boundsForSpanWidth(LatLng midpoint, float targetSpanWidth){
    LatLng east = offsetLongitude(midpoint, -targetSpanWidth);
    LatLng west = offsetLongitude(midpoint, targetSpanWidth);
    LatLngBounds newBounds = new LatLngBounds(west, east);
    return newBounds;
}

然而,当我用一个目标跨度为5000米的点(不接近极点或任何东西)来称呼它时,我得到了两个相距约6170米的点。为什么?

不可能从经纬度获得精确的偏移量(以米为单位)。这将假定地球是一个完美而光滑的球体,但事实并非如此

如果你想减少你的误差,你应该根据你的纬度调整每度公里数。您链接的答案估计为每度111公里,但这取决于您的纬度(特别是经度方向)。见下表:

Lat    1°Lat≃       1°Lon≃
0°   110.574 km   111.320 km
15°  110.649 km   107.550 km
30°  110.852 km   96.486 km
45°  111.132 km   78.847 km
60°  111.412 km   55.800 km
75°  111.618 km   28.902 km
90°  111.694 km   0.000 km
参考:


我希望这有帮助

您可以使用谷歌地图Android API实用程序库()中的
computeOffset
方法:

公共静态LatLng计算偏移量(LatLng from、双距离、双航向)

返回从指定航向中的原点移动一段距离(以从北顺时针方向角度表示)所产生的纬度

参数:

  • from-从中开始的板条
  • 距离-旅行的距离
  • 航向-从北顺时针方向以度为单位的航向
在您的情况下(距离参数以米为单位):


图书馆工作了。我想知道为什么我的代码不工作,但无论如何,问题解决了。
LatLng east = SphericalUtil.computeOffset(midpoint, 500, 90); // Shift 500 meters to the east
LatLng west = SphericalUtil.computeOffset(midpoint, 500, 270); // Shift 500 meters to the west