2011-08-19 22 views
0

我從@DanS下面的代碼,在此鏈接how-to-display-a-map-still-image-file-with-a-moving-current-location如何計算斜邊和軸承

onCurrentPosition(Location current){ 
    double hypotenuse = upperLeft.distanceTo(current); 
    double bearing = upperLeft.bearingTo(current); 
    double currentDistanceX = Math.cos(bearing) * hypotenuse; 
    //      "percentage to mark the position" 
    double currentPixelX = (currentDistanceX/upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth; 

    moveIndicatorX(currentPixelX); 
} 

這裏是值:

  • 電流:41.850033,-87.65005229999997
  • upperLeft: 41.866514127810355,-87.6720142364502
  • lowerRight:41.83397145565242,-87.62824058532715
  • mapWidth:512×512像素

這裏有計算器在線位置,斜邊(距離),軸承(方位角)

我得到了結果:

  • hyp otenuse = 2581
  • 軸承= 135.21
  • currentDistanceX = -2562
  • currentPixelX = 311.9

想問一下你們到:

  1. 確認,如果我的計算結果正確。
  2. 關於如何計算currentPixelY(另一個點)?

順便說一句,我打算用它來計算給定現實生活中的位置,經緯度(電流)對與粘接靜止圖像的upperLeft和lowerRight角落到現實生活中我的靜態圖像地圖經緯度。

如果你想看到實際的&預期輸出,並且想要輕鬆理解整個圖片。請參考此鏈接 - >How to mark the current location into a still image map

回答

1

這是我用實際的代碼,而不是僞代碼以前發佈的:

Location upperLeft = new Location(""); 
upperLeft.setLatitude(41.866514127810355); 
upperLeft.setLongitude(-87.6720142364502); 
Location lowerRight = new Location(""); 
lowerRight.setLatitude(41.83397145565242); 
lowerRight.setLongitude(-87.62824058532715); 
Location current = new Location(""); 
current.setLatitude(41.850033); 
current.setLongitude(-87.65005229999997); 
double hypotenuse = upperLeft.distanceTo(current); 
double bearing = upperLeft.bearingTo(current); 
double currentDistanceX = Math.cos(bearing * Math.PI/180.0) * hypotenuse; 
//      "percentage to mark the position" 
double totalHypotenuse = upperLeft.distanceTo(lowerRight); 
double totalDistanceX = totalHypotenuse * Math.cos(upperLeft.bearingTo(lowerRight) * Math.PI/180.0); 
double currentPixelX = currentDistanceX/totalDistanceX * 512; 

System.out.println(currentPixelX); // 259.3345493341548 

你的答案計算看起來有點假。 要計算Y更改,請複製使用Math.sin()而不是Math.cos()的所有X標記的計算和變量。

+0

你會介意如何顯示圖像映射並標記給定的當前座標嗎?你有樣本eclipse項目分享嗎? – eros

+0

你有任何你已經開始的代碼嗎? –