2013-03-10 28 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