【问题标题】:Calculate latitude longitude for added height计算纬度经度以增加高度
【发布时间】:2015-05-12 09:48:05
【问题描述】:

我想在安卓谷歌地图上画一个折线图。 我有路径的 gps 坐标,我想用线的高度在地图上显示汽车的速度。

看到这张图片 像这样的,

对于每个 gps (lat,lng) 点,我想添加一些高度并计算相应的 gps(lat,lng) 点。我想在 3D 视图中显示这个,所以当相机位置改变时我必须改变点,但第一步是计算增加高度的 gps 点。

例如

ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
basePoints.add(new LatLng(53.262688, -2.500792));
basePoints.add(new LatLng(53.262758, -2.500897));
basePoints.add(new LatLng(53.262789, -2.501087));
basePoints.add(new LatLng(53.262798, -2.501229));
basePoints.add(new LatLng(53.262785, -2.501414));
basePoints.add(new LatLng(53.262760, -2.501594));
basePoints.add(new LatLng(53.262707, -2.501811));
basePoints.add(new LatLng(53.262655, -2.501943));

ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
topPoints.add(new LatLng(53.262939, -2.500779));
topPoints.add(new LatLng(53.262975, -2.500916));
topPoints.add(new LatLng(53.262914, -2.501098));
topPoints.add(new LatLng(53.263055, -2.501248));
topPoints.add(new LatLng(53.262925, -2.501439));
topPoints.add(new LatLng(53.263045, -2.501581));
topPoints.add(new LatLng(53.262907, -2.501844));
topPoints.add(new LatLng(53.263002, -2.502015));

知道我该怎么做吗? 谢谢

【问题讨论】:

    标签: android gps latitude-longitude


    【解决方案1】:

    根据您提供的link,我已经为您实现了这个。

    final ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
    basePoints.add(new LatLng(53.262688, -2.500792));
    basePoints.add(new LatLng(53.262758, -2.500897));
    basePoints.add(new LatLng(53.262789, -2.501087));
    basePoints.add(new LatLng(53.262798, -2.501229));
    basePoints.add(new LatLng(53.262785, -2.501414));
    basePoints.add(new LatLng(53.262760, -2.501594));
    basePoints.add(new LatLng(53.262707, -2.501811));
    basePoints.add(new LatLng(53.262655, -2.501943));
    
    final ArrayList<Double> speedPoints = new ArrayList<Double>();
    speedPoints.add(7.955734692);
    speedPoints.add(8.761378798);
    speedPoints.add(11.07760474);
    speedPoints.add(13.69594751);
    speedPoints.add(15.50864695);
    speedPoints.add(16.01217576);
    speedPoints.add(15.60935179);
    speedPoints.add(15.71005663);
    
    LatLngBounds.Builder bounds = new LatLngBounds.Builder();
    for(int i=0;i<basePoints.size();i++)
    {
        bounds.include(basePoints.get(i));
    }
    map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 300,300,0));
    map.setOnCameraChangeListener(new OnCameraChangeListener() {
        @Override
        public void onCameraChange(CameraPosition arg0)
        {
            map.clear();
            ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
            for(int i=0;i<basePoints.size();i++)
            {
                topPoints.add(moveByDistance(basePoints.get(i), speedPoints.get(i)*3,map.getCameraPosition().bearing));
            }
            PolylineOptions topPO = new PolylineOptions();
            topPO.addAll(topPoints).width(5).color(Color.BLUE).geodesic(true);
            map.addPolyline(topPO);
            for(int i=0;i<basePoints.size()-1;i++)
            {
                map.addPolygon(new PolygonOptions().add(basePoints.get(i),topPoints.get(i),topPoints.get(i+1),basePoints.get(i+1),basePoints.get(i)).fillColor(Color.YELLOW).strokeColor(Color.YELLOW));
            }
        }
    
    });
    
    /**
     * Move a LatLng-Point into a given distance and a given angle (0-360,
     * 0=North).
     */
    public static LatLng moveByDistance(LatLng startGp, double distance,double angle) {
        /*
         * Calculate the part going to north and the part going to east.
         */
        double arc = Math.toRadians(angle);
        double toNorth = distance * Math.cos(arc);
        double toEast = distance * Math.sin(arc);
        double lonDiff = meterToLongitude(toEast, startGp.latitude);
        double latDiff = meterToLatitude(toNorth);
        return new LatLng(startGp.latitude + latDiff, startGp.longitude + lonDiff);
    }
    
    private static double meterToLongitude(double meterToEast, double latitude) {
        double latArc = Math.toRadians(latitude);
        double radius = Math.cos(latArc) * EARTHRADIUS;
        double rad = meterToEast / radius;
        double degrees = Math.toDegrees(rad);
        return degrees;
    }
    
    private static double meterToLatitude(double meterToNorth) {
        double rad = meterToNorth / EARTHRADIUS;
        double degrees = Math.toDegrees(rad);
        return degrees;
    }
    

    我希望它能帮助你实现这一点。

    【讨论】:

    • 这正是我想做的,我没想到会那么容易。 CameraChangeListener 很容易实现。谢谢:)
    【解决方案2】:

    计算一米是多少度:

    赤道:

    360 度, 有 40.000 000 米的圆周。

    所以一米左右

    double static final METERS_PER_DEGREE = 360.0 / 40 000 000;
    

    现在将纬度偏移 3 米:

    lat = lat + 3 * METERS_PER_DEGREE.
    

    偏移经度时,必须乘以cos(Math.toRadians(latitude);

    double oneMeterLongitudeInDegrees = METERS_PER_DEGREE * cos(Math.toRadians(latitude);
    
    lonNew = lonOld + 3 * oneMeterLongitudeInDegrees 
    

    【讨论】:

    • 谢谢,我正在查看this 的答案,似乎运行良好
    猜你喜欢
    • 2010-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    相关资源
    最近更新 更多