我有一个
注意:我不是在寻找如何移动Google地图相机,我知道如何做到这一点。
我尝试过:
LatLng
对象,我想将它的坐标向东移动500米。我找不到内置的方法来实现这一点。我看过https://gis.stackexchange.com/a/2964,但我的结果太不准确(约15%)无法实际使用。如何进行精确的移位?注意:我不是在寻找如何移动Google地图相机,我知道如何做到这一点。
我尝试过:
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 米 左右的点。为什么?