如何将标记旋转到另一个点(位置)



我基本上想知道如何计算标记并将其旋转到另一个位置点(Lat&Lng)。

这是使用Android版的谷歌地图API v2。

在创建位图描述符并显示标记之前,为标记使用自定义位图并用矩阵旋转它。

适用于值为90270的情况,但类似的方法应该适用于您

Matrix matrix = new Matrix();
matrix.postRotate(orientation); // anti-clockwise
Bitmap rotatedBitmap = Bitmap.createBitmap(bm, 0, 0,
bm.getWidth(),  bm.getHeight(), matrix, true);
bm = rotatedBitmap.copy(rotatedBitmap.getConfig(), true);
BitmapDescriptor bd = BitmapDescriptorFactory.fromBitmap(bm);
markeroptions.icon(bd);

这是来自github 上的谷歌地图实用程序

https://github.com/googlemaps/android-maps-utils

/**
 * Returns the heading from one LatLng to another LatLng. Headings are
 * expressed in degrees clockwise from North within the range [-180,180).
 * @return The heading in degrees clockwise from north.
 */
public static double computeHeading(LatLng from, LatLng to) {
    // http://williams.best.vwh.net/avform.htm#Crs
    double fromLat = toRadians(from.latitude);
    double fromLng = toRadians(from.longitude);
    double toLat = toRadians(to.latitude);
    double toLng = toRadians(to.longitude);
    double dLng = toLng - fromLng;
    double heading = atan2(
            sin(dLng) * cos(toLat),
            cos(fromLat) * sin(toLat) - sin(fromLat) * cos(toLat) * cos(dLng));
    return wrap(toDegrees(heading), -180, 180);
}

相关内容

最新更新