2013-03-10 18 views
-2

我有兩個Geopoints從距離值獲取經緯度值從描繪路徑中的Android

GeoPoint gp1; 
GeoPoint gp2; 

我也有這兩個geopoints之間的距離。截至目前它是174公里。我需要這兩個地理點之間準確的中間地理位置,所以我如何獲得Middle GeoPoint。

以上兩種的GeoPoint是路線繪製這是不直這樣的一部分,我需要描繪路徑不是直線的中間點

我的代碼:

List<GeoPoint> _geopoints = decodePoly(_path); 
GeoPoint gp1; 
GeoPoint gp2; 
gp2 = _geopoints.get(0); 
System.out.println("gp2 "+gp2);           
System.out.println("_geopoints"+_geopoints.size()); 
System.out.println("_midgeopoint"+_geopoints.size()/2);  
mGeoPointMiddleOne=_geopoints.get(_geopoints.size()/2); 


private List<GeoPoint> decodePoly(String encoded) { 

     List<GeoPoint> poly = new ArrayList<GeoPoint>(); 
     int index = 0, len = encoded.length(); 
     int lat = 0, lng = 0; 

     while (index < len) { 
      int b, shift = 0, result = 0; 
      do { 
       b = encoded.charAt(index++) - 63; 
       result |= (b & 0x1f) << shift; 
       shift += 5; 
      } while (b >= 0x20); 
      int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
      lat += dlat; 

      shift = 0; 
      result = 0; 
      do { 
       b = encoded.charAt(index++) - 63; 
       result |= (b & 0x1f) << shift; 
       shift += 5; 
      } while (b >= 0x20); 
      int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1)); 
      lng += dlng; 

      GeoPoint p = new GeoPoint((int) (((double) lat/1E5) * 1E6), 
        (int) (((double) lng/1E5) * 1E6)); 
      poly.add(p); 
     } 

     return poly; 
    } 

上述功能decoePoly(路徑)負責在兩個地點之間繪製路線,所以我得到兩點之間的路線。

,我也得到這兩個geopoints之間的距離調用谷歌地圖API繪製路線,低於

http://maps.googleapis.com/maps/api/directions/xml? origin=52.31,16.71&destination=51.27,6.75&sensor=false 

,所以我在Web服務

所以我需求量的得到標記兩點之間的距離我怎樣才能獲得從這條路線的中距離值緯度經度?

+0

我添加了一個鏈接到我的回答。請看看它。 – hakiko 2013-03-10 14:39:42

回答

0

你在找什麼是「座標幾何」,你正在尋找「直線方程」。

在這裏,一個有趣的link在互聯網上。

+0

我的要求是找到鋸齒狀不在直線上的路線中點。 – 2013-03-10 14:39:30

+0

你的意思是,沿路徑的中點?在這種情況下,編輯你的問題,它的誤導和浪費人們的時間。 – Siddharth 2013-03-10 14:46:37

0

如果您有兩個GeoPoint,我認爲距離值不是必需的。分析幾何說,如果你知道兩點的座標,你可以簡單地計算中點。

如果您有特定的路線不是直線。

看到這個頁面:GO

enter image description here

+1

大圓或正方向距離是球體表面上任意兩點之間的最短距離。你所展示的是一種近似值,可用於短距離。 OP需要意識到這一點。 – 2013-03-10 14:20:13

+0

@jimmcnamara:我的要求是找到鋸齒狀不在直線上的路線中點 – 2013-03-10 14:33:37

相關問題