在我的应用程序中,我使用MapKit中的卫星图像。我大部分时间使用2D卫星地图,使用的是音高为0的MKMapCamera。用户可以更改为一个音高为80的3D地图和一个更低的距离设置,因为我不需要看到太远在3D。
这在芝加哥大都会区非常好,但在我尝试过的更多的农村地区(阿拉巴马州,西德克萨斯州,纳什维尔和亚特兰大以外的一些地方)则完全没有效果。在这些区域,地图中的音高变化似乎是非常有限的,因此最终的结果是,随着距离的减小,相机直接俯冲到地面上,而不是向下移动,为预期的美丽3D视图进行平移。就像我说的,这在芝加哥及其周边地区非常有效。
我怀疑这是因为用于更极端(80度) 3D视图的信息在许多领域是有限的(可能只适用于那些具有天桥可用性的区域,如https://www.apple.com/ios/feature-availability/#maps-flyover ?)。
是否有一种方式以编程方式检查这种类型的3D视图在给定位置是否可用?
我希望能够禁用3D控件的位置,其中的3D视图是不可用的。"isPitchEnabled“属性只是查看是否启用了音高调整,而不是查看所请求的音高更改是否在特定位置有效。
下面是我使用的代码片段,它在某些位置工作得很好:
设置MKMapCamera -
var mapCamera: MKMapCamera {
// MARK: This sets the camera perspective and position. It may be generally a 2D view showing the map from directly above or it may be a 3D view looking down the line
return MKMapCamera(
lookingAtCenter: cameraCenter(),
fromDistance: cameraDistanceUsed * locations.cameraZoom,
pitch: locations.cameraAngle,
heading: locations.bearing()
)
}
func cameraCenter() -> CLLocationCoordinate2D {
// MARK: This sets the center of the map
if locations.cameraZoom == CameraZoom.birdsEye.rawValue {
// In the 2D (birds-eye) view, set the camera center to be the midpoint of the scene so that the entire scene is visible.
return locations.midpoint.scene
} else {
// In the 3D view, set the camera center to be the midpoint between the user and the target so that the map is aligned with the direction of the user
return locations.midpoint.target
}
}制造MapView -
func makeUIView(context: Context) -> MKMapView {
// MARK: This creates the satellite map
let mapView = MKMapView()
// Sets the map type to Satellite view
mapView.preferredConfiguration = MKImageryMapConfiguration(elevationStyle: .realistic)
// Shows the user's location on the map
mapView.showsUserLocation = true
// Sets the map camera and the coordinator
mapView.delegate = context.coordinator
mapView.camera = mapCamera
mapView.isPitchEnabled = true
//
DispatchQueue.main.async {
self.courseMap = mapView
}
return mapView
}更改2D/3D值的枚举-
enum CameraAngle: Double {
// MARK: This sets the value for the camera angle on the map.
// Degrees of "0" means the camera is directly above the map, in a 2D "birds-eye" view. Increasing the degrees of results in a more 3D view looking down the target line.
case birdsEye = 0
case threeD = 80
}
enum CameraZoom: Double {
// MARK: This sets the value for the camera zoom on the map.
// Zoom factor of "2.2" is used for the 2D "birds-eye" view. A lower zoom factor is used for 3D view looking down the target line since you don't need to see too far in the distance.
case birdsEye = 2.2
case threeD = 0.5
}在2D和3D之间切换-
Button {
// Change the camera angle and distance from the ground to create the 3D view where available
locations.cameraAngle = CameraAngle.threeD.rawValue
locations.cameraZoom = CameraZoom.threeD.rawValue
} label: {
Image(systemName: "chevron.up")
.font(.title)
}
Button {
// Raise the camera and set the angle to 0º to create the 2D "bird's eye" view of the map
locations.cameraAngle = CameraAngle.birdsEye.rawValue
locations.cameraZoom = CameraZoom.birdsEye.rawValue
} label: {
Image(systemName: "chevron.down")
.font(.title)
}有什么想法,我可以如何检查3D可用性,以便我可以禁用按钮的位置需要?
发布于 2022-11-16 18:47:19
在AskApple地图问答环节中,我确认3D卫星只适用于某些地区。这是完全可以理解的,所以我想在不支持3D视图的地方以编程方式禁用3D功能。不幸的是,AskApple问答还指出,目前还没有一种方法来确定某一地点是否有3D卫星。我向Apple提交了一个增强建议,但目前还没有办法以编程方式禁用3D。
https://stackoverflow.com/questions/74112562
复制相似问题