2011-05-02 241 views
7

我需要計算給定點的緯度和經度。計算距離另一緯度/經度點米的緯度和經度

我知道參考點的經度和緯度,以及從參考點指示x軸和y軸上的米的值。 從這些數據開始,我必須找到經緯度。

我搜索了類似的問題,但它看起來像大多數問題都是關於找到兩個緯度/長點之間的距離。我需要做相反的事情。

我該怎麼辦? 我使用Java

+0

**歡迎計算器-90!**問候。 – 2011-05-02 14:22:23

回答

9

以下是此類問題的最佳出發點:Aviation Formulary。他們擁有做這類事情的所有公式。

從這些公式中,我創建了自己的Java util類。它使用了很多內部的東西,所以我不能在這裏發佈實際的類,但給你一些關於如何將公式中的知識轉換爲Java代碼的例子。

我這裏還有一些基本的方法:

/** 
* the length of one degree of latitude (and one degree of longitude at equator) in meters. 
*/ 
private static final int DEGREE_DISTANCE_AT_EQUATOR = 111329; 
/** 
* the radius of the earth in meters. 
*/ 
private static final double EARTH_RADIUS = 6378137; //meters 
/** 
* the length of one minute of latitude in meters, i.e. one nautical mile in meters. 
*/ 
private static final double MINUTES_TO_METERS = 1852d; 
/** 
* the amount of minutes in one degree. 
*/ 
private static final double DEGREE_TO_MINUTES = 60d; 


/** 
* This method extrapolates the endpoint of a movement with a given length from a given starting point using a given 
* course. 
* 
* @param startPointLat the latitude of the starting point in degrees, must not be {@link Double#NaN}. 
* @param startPointLon the longitude of the starting point in degrees, must not be {@link Double#NaN}. 
* @param course  the course to be used for extrapolation in degrees, must not be {@link Double#NaN}. 
* @param distance  the distance to be extrapolated in meters, must not be {@link Double#NaN}. 
* 
* @return the extrapolated point. 
*/ 
public static Point extrapolate(final double startPointLat, final double startPointLon, final double course, 
           final double distance) { 
    // 
    //lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc)) 
    //dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat)) 
    //lon=mod(lon1+dlon +pi,2*pi)-pi 
    // 
    // where: 
    // lat1,lon1 -start pointi n radians 
    // d   - distance in radians Deg2Rad(nm/60) 
    // tc   - course in radians 

    final double crs = Math.toRadians(course); 
    final double d12 = Math.toRadians(distance/MINUTES_TO_METERS/DEGREE_TO_MINUTES); 

    final double lat1 = Math.toRadians(startPointLat); 
    final double lon1 = Math.toRadians(startPointLon); 

    final double lat = Math.asin(Math.sin(lat1) * Math.cos(d12) 
     + Math.cos(lat1) * Math.sin(d12) * Math.cos(crs)); 
    final double dlon = Math.atan2(Math.sin(crs) * Math.sin(d12) * Math.cos(lat1), 
     Math.cos(d12) - Math.sin(lat1) * Math.sin(lat)); 
    final double lon = (lon1 + dlon + Math.PI) % (2 * Math.PI) - Math.PI; 

    return new Point(Math.toDegrees(lat), Math.toDegrees(lon)); 
} 

/** 
* calculates the length of one degree of longitude at the given latitude. 
* 
* @param latitude the latitude to calculate the longitude distance for, must not be {@link Double#NaN}. 
* 
* @return the length of one degree of longitude at the given latitude in meters. 
*/ 
public static double longitudeDistanceAtLatitude(final double latitude) { 

    final double longitudeDistanceScaleForCurrentLatitude = Math.cos(Math.toRadians(latitude)); 
    return DEGREE_DISTANCE_AT_EQUATOR * longitudeDistanceScaleForCurrentLatitude; 
} 
+2

這是否回答你的問題? - 那麼請接受答案。 – BertNase 2011-05-26 04:27:50

0

這是不是一個真正的答案,但在評論欄中太短,我要發佈,而這一結果提出了相當高的,當我用Google搜索一個答案。上面的BertNase代碼很好,我正在使用它。然而,圍繞邊緣案例有些奇怪。我並不是100%確定代碼是錯誤的,因爲我仍在學習地理信息,但是我從我寫的junit測試用例中添加了參數。例如經度從180變爲當我南下100M的(情況10)

/*0*/ { inputOf(0.0, 0.0), NORTH, shouldGiveAnswerOf(0.0009, 0.0) }, 
/*1*/ { inputOf(0.0, 0.0), SOUTH, shouldGiveAnswerOf(-0.0009, 0.0) }, 
/*2*/ { inputOf(0.0, 0.0), WEST, shouldGiveAnswerOf(0.0, -0.0009) }, 
/*3*/ { inputOf(0.0, 0.0), EAST, shouldGiveAnswerOf(0.0, 0.0009) }, 

/*4*/ { inputOf(90.0, 180.0), NORTH, shouldGiveAnswerOf(89.9991, -180.0) }, 
/*5*/ { inputOf(0.0, 180.0), NORTH, shouldGiveAnswerOf(0.0009, -180.0) }, 
/*6*/ { inputOf(-90.0, 180.0), NORTH, shouldGiveAnswerOf(-89.9991, -180.0) }, 
/*7*/ { inputOf(90.0, -180.0), NORTH, shouldGiveAnswerOf(89.9991, -180.0) }, 
/*8*/ { inputOf(0.0, -180.0), NORTH, shouldGiveAnswerOf(0.0009, -180.0) }, 
/*9*/ { inputOf(-90.0, -180.0), NORTH, shouldGiveAnswerOf(-89.9991, -180) }, 

/*10*/ { inputOf(90.0, 180.0), SOUTH, shouldGiveAnswerOf(89.9991, -90.0) }, 
/*11*/ { inputOf(0.0, 180.0), SOUTH, shouldGiveAnswerOf(-0.0009, -180.0) }, 
/*12*/ { inputOf(-90.0, 180.0), SOUTH, shouldGiveAnswerOf(-89.9991, -90.0) }, 
/*13*/ { inputOf(90.0, -180.0), SOUTH, shouldGiveAnswerOf(89.9991, -90.0) }, 
/*14*/ { inputOf(0.0, -180.0), SOUTH, shouldGiveAnswerOf(-0.0009, -180.0) }, 
/*15*/ { inputOf(-90.0, -180.0), SOUTH, shouldGiveAnswerOf(-89.9991, -90) }, 

/*16*/ { inputOf(90.0, 180.0), EAST, shouldGiveAnswerOf(89.9991, -90.0) }, 
/*17*/ { inputOf(0.0, 180.0), EAST, shouldGiveAnswerOf(0.0, -179.9991) }, 
/*18*/ { inputOf(-90.0, 180.0), EAST, shouldGiveAnswerOf(-89.9991, -90.0) }, 
/*19*/ { inputOf(90.0, -180.0), EAST, shouldGiveAnswerOf(89.9991, -90.0) }, 
/*20*/ { inputOf(0.0, -180.0), EAST, shouldGiveAnswerOf(0.0, -179.9991) }, 
/*21*/ { inputOf(-90.0, -180.0), EAST, shouldGiveAnswerOf(-89.9991, -90) }, 

/*22*/ { inputOf(10.0, 5.0), NORTH, shouldGiveAnswerOf(10.0009, 5.0) }, 
/*23*/ { inputOf(10.0, 5.0), SOUTH, shouldGiveAnswerOf(9.9991, 5.0) }, 
/*24*/ { inputOf(10.0, 5.0), WEST, shouldGiveAnswerOf(10.0, 4.999086) }, 
/*25*/ { inputOf(10.0, 5.0), EAST, shouldGiveAnswerOf(10.0, 5.000914) }, 

/*26*/ { inputOf(10.0, 5.0), NORTH_EAST, shouldGiveAnswerOf(10.000636, 5.000646) }, 
相關問題