2015-05-22 27 views
-1

我正在開發Ios應用程序的Android版本,該應用程序是由我開發的,它們遇到了兩種平臺上Google Maps API差異的問題。在Ios中,我可以使用方法:GMSGeometryOffset。但是,它不在Android API中。因此,我正在尋找這種方法的替代方案,以便我可以根據當前位置,方向/方位和距離/半徑計算新的位置。iOS替代iOS Google Maps API GMSGeometryOffset

我正在用它畫圓圈,同時避免雞蛋形狀。我的代碼到目前爲止如下所示。然而,除非當前位置直接位於赤道上方,否則它會給我一個雞蛋形狀。

for(double angle = 0; angle < 2*Math.PI; angle = angle+ Math.PI/resolutionCircle) 
     { 
      latitude = position.latitude + (radiusCircle * Math.sin(angle)); 
      longitude = position.longitude + (radiusCircle * Math.cos(angle)); 

      inner.add(new LatLng(latitude, longitude)); 
     } 

回答

0

在Google Maps Android API實用程序庫中有一個computeOffset方法。

這是一個靜態方法:

public static LatLng computeOffset(LatLng from, 
        double distance, 
        double heading) 

它返回經緯度從原點在指定的標題(順時針從北以度表示)移動的距離得到的。

有關Google Maps Android API公用程序庫的更多詳細信息,請參閱this documentation

谷歌地圖GitHub page還提供了詳細的實施:

public static LatLng computeOffset(LatLng from, double distance, double heading) { 
     distance /= EARTH_RADIUS; 
     heading = toRadians(heading); 
     // http://williams.best.vwh.net/avform.htm#LL 
     double fromLat = toRadians(from.latitude); 
     double fromLng = toRadians(from.longitude); 
     double cosDistance = cos(distance); 
     double sinDistance = sin(distance); 
     double sinFromLat = sin(fromLat); 
     double cosFromLat = cos(fromLat); 
     double sinLat = cosDistance * sinFromLat + sinDistance * cosFromLat * cos(heading); 
     double dLng = atan2(
       sinDistance * cosFromLat * sin(heading), 
       cosDistance - sinFromLat * sinLat); 
     return new LatLng(toDegrees(asin(sinLat)), toDegrees(fromLng + dLng)); 
    } 
+0

有多大應該是距離?以米或千米爲單位..如果我想考慮從地圖中心的角落? –