2015-05-22 25 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

有多大应该是距离?以米或千米为单位..如果我想考虑从地图中心的角落? –