2016-10-01 146 views
0

所以我想知道是否有現有的代碼/庫允許我計算一對新的GPS座標:距離,一對緯度和longituide和軸承。從一組座標和距離計算新的GPS座標?

我希望你們能給我見解。

乾杯!

+0

[這裏的一個鏈接](http://stackoverflow.com/questions/37348207/find-location-距我的位置1公里的南緯度/ 37349396#37349396)到以前的答案。你可以使用那裏提到的庫(如果許可證是好的),或者只是抓住基本想法並編寫自己的代碼。 –

+0

嘿謝謝你!我在找什麼 – TheQ

回答

0

給我的答案是從這個鏈接:stackoverflow.com/questions/37348207/find-location-1-km-away-in-180-degree-south-from-my-location/37349396# 37349396

使用以下庫:https://github.com/JavadocMD/simplelatlng 但這計算方法如下:

/** 
    * <p> 
    * Calculate the end point of traveling along a great-circle path from a 
    * given starting point with a given intitial bearing for a known distance. 
    * </p> 
    * 
    * @param start 
    *   the starting point. 
    * @param initialBearing 
    *   the initial bearing. 
    * @param distance 
    *   the distance to travel. 
    * @param unit 
    *   the unit in which distance is measured. 
    * @return the end point. 
    */ 
    public static LatLng travel(LatLng start, double initialBearing, double distance, 
      LengthUnit unit) { 
     double bR = Math.toRadians(initialBearing); 
     double lat1R = Math.toRadians(start.getLatitude()); 
     double lon1R = Math.toRadians(start.getLongitude()); 
     double dR = distance/LatLngConfig.getEarthRadius(unit); 

     double a = Math.sin(dR) * Math.cos(lat1R); 
     double lat2 = Math.asin(Math.sin(lat1R) * Math.cos(dR) + a * Math.cos(bR)); 
     double lon2 = lon1R 
       + Math.atan2(Math.sin(bR) * a, Math.cos(dR) - Math.sin(lat1R) * Math.sin(lat2)); 
     return new LatLng(Math.toDegrees(lat2), Math.toDegrees(lon2)); 
    }