从Android中的绘图路线的距离值中获取纬度 - 经度值

时间:2013-03-10 14:10:39

标签: android

我有两个Geopoints

GeoPoint gp1; 
GeoPoint gp2;

这两个地理位置之间也有距离。截至目前,它是174公里。我需要在这两个地理位置之间准确的中间位置,所以我怎么能得到Middle GeoPoint。

以上两个GeoPoint是Route Draw的一部分,它不是直的所以我需要绘制路线的中间点而不是直线

我的代码:

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(path)负责在两个地理点之间绘制路线,这样我得到两点之间的路线。

我也可以通过调用谷歌地图api绘制路线来获得这两个地理位置之间的距离

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

所以我从Web服务中的标记获得两点之间的距离

所以我的要求是如何从这条路线获得中距离值的纬度 - 经度?

2 个答案:

答案 0 :(得分:0)

您正在寻找的是“协调几何”,您正在寻找“直线方程”。

接下来,互联网上有一个有趣的link

答案 1 :(得分:0)

如果您有两个GeoPoints,我认为不需要距离值。分析几何学说,如果你知道两点的坐标,你可以简单地计算中点。

如果您的特定路线不是直线。

请参阅此页:GO

enter image description here