我有兩個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服務
所以我需求量的得到標記兩點之間的距離我怎樣才能獲得從這條路線的中距離值緯度經度?
我添加了一個鏈接到我的回答。請看看它。 – hakiko 2013-03-10 14:39:42