2011-10-06 72 views
0

我試圖讓代碼的一部分工作(類似於我下面的內容),以便OBJECT_LOC和CONVERTED_LOC完全相同。我認爲代碼與我正在做的事情相當直接,但由於某種原因,它們不是平等的?我究竟做錯了什麼? (您可以在下面看到輸出)。緯度/長度和距離的Java問題

import com.bbn.openmap.LatLonPoint; 
import com.bbn.openmap.proj.Length; 
import com.bbn.openmap.proj.coords.DMSLatLonPoint; 

public class Test { 

     /** 
     * @param args 
     */ 
     public static void main(String[] args) { 

       // 45:20:00.0N/24:00:00.0E 
       LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false, 
           24, 00, 00.0f).getLatLonPoint(); 

       System.out.println("BASE_LOC: " + BASE_LOC); 

       LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.346556); 

       System.out.println("OBJECT_LOC: " + OBJECT_LOC); 

       float distanceX = BASE_LOC.distance(new LatLonPoint(BASE_LOC 
           .getLatitude(), OBJECT_LOC.getLongitude())); 

       float distanceY = BASE_LOC.distance(new LatLonPoint(OBJECT_LOC 
           .getLatitude(), BASE_LOC.getLongitude())); 


       LatLonPoint CONVERTED_POINT = new LatLonPoint(BASE_LOC.getLatitude() 
           + Length.DECIMAL_DEGREE.fromRadians(distanceY), 
           BASE_LOC.getLongitude() 
               + Length.DECIMAL_DEGREE.fromRadians(distanceX)); 

       System.out.println("CONVERTED_POINT " + CONVERTED_POINT); 

     } 
} 

輸出:

BASE_LOC: LatLonPoint[lat=45.333332,lon=24.0] 
OBJECT_LOC: LatLonPoint[lat=52.749355,lon=26.346556] 
CONVERTED_POINT LatLonPoint[lat=52.749355,lon=25.649527] 

回答

1

在看過API文檔和一些關於地理的文獻後,它看起來像找出第二點的方法是有缺陷的。正確的做法是使用距離和方位(方位角)。以下是更正後的代碼:

import com.bbn.openmap.LatLonPoint; 
import com.bbn.openmap.proj.coords.DMSLatLonPoint; 

public class TestProgram { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) { 

      // 45:20:00.0N/24:00:00.0E 
      LatLonPoint BASE_LOC = new DMSLatLonPoint(false, 45, 20, 00.0f, false, 24, 00, 00.0f).getLatLonPoint(); 
      System.out.println("BASE_LOC: " + BASE_LOC); 

      LatLonPoint OBJECT_LOC = new LatLonPoint(52.749355, 26.0); 
      System.out.println("OBJECT_LOC: " + OBJECT_LOC); 

      float distance = BASE_LOC.distance(OBJECT_LOC); 
      float az = BASE_LOC.azimuth(OBJECT_LOC); 

      LatLonPoint CONVERTED_POINT = BASE_LOC.getPoint(distance, az); 

      System.out.println("CONVERTED_POINT " + CONVERTED_POINT); 

    } 

}

的一些信息可以在這裏找到 - 故意http://www.movable-type.co.uk/scripts/latlong.html

0

對於它的價值,當你做你BASE_LOC.distance()調用,你OBJECT_LOC/BASE_LOC之間的爭論交換兩個距離。其中一個是OBJECT_LOC/BASE_LOC,另一個是BASE_LOC/OBJECT_LOC。

+0

那。在第一次調用中,我將BASE_LOC設置爲緯度,這樣我就可以從OBJECT_LOC中獲得X距離。在下一次調用中,我將BASE_LOC設置爲經度,因此我可以從OBJECT_LOC – systemoutprintln

相關問題