🧭 指向标

一个微型包 (µPackage),用于显示一个 SwiftUI 视图,该视图自动旋转以始终指向指定的坐标。它就像一个指南针,只不过它指向您喜欢的任何位置。

使用方法

您需要一个观测对象,该对象发布位置更改和当前航向信息。具体来说,您可能需要在您的 CLLocationManagerDelegate 中实现以下内容:

然后,只需创建一个新的 HeadingIndicator 视图,告诉它指向哪里并设置它的显示方式。请确保视图默认情况下指向上方,否则它将无法正确旋转。

import HeadingIndicator

HeadingIndicator(
    currentLocation: /* The device's current location. */,
    currentHeading: /* The device's current heading. */,
    targetLocation: /* The location to point to. */
) {
    Image(systemName: "arrow.up.circle")
}