我有一個LatLng
對象,我想將它的座標向東移動500米。我無法找到一個內置的方法。我看過https://gis.stackexchange.com/a/2964,但是我的結果實際上太不準確(約15%)。我怎樣才能做出米的精確轉變?在Android中偏移LatLng一定數量的米
注:我是不是尋找轉移谷歌地圖相機,我知道該怎麼做。
我已經試過:
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米分開。爲什麼?
圖書館工作。我想知道爲什麼我的代碼不工作,但無論如何,問題解決了。 –