MKMapCamera俯仰调整在某些位置不起作用



在我的应用程序中,我使用MapKit中的卫星图像。我大部分时间使用的是间距为0的MKMapCamera二维卫星地图。用户可以更改为间距为80且距离设置低得多的3D地图,因为我不需要在3D中看太远。

这在芝加哥大都市地区效果很好,但在我尝试过的更多农村地区(阿拉巴马州、得克萨斯州西部以及纳什维尔和亚特兰大以外的一些地方(却一点也不好。在这些区域,地图中的间距变化似乎非常有限,因此最终结果是,随着距离的减小,相机只是直接向下俯冲到地面上,而不是向下移动并向外平移以获得预期的美丽3D视图。正如我所说,这在芝加哥地区及其周边地区非常有效。

我怀疑这是因为用于更极端(80度(三维视图的信息在许多地区都是有限的(可能只适用于那些有立交桥可用性的地区,如https://www.apple.com/ios/feature-availability/#maps-天桥?(。

有没有一种方法可以通过编程检查这种类型的三维视图在给定位置是否可用

我希望能够在三维视图不可用的位置禁用三维控件。";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可用性,以便在需要的位置禁用按钮,有什么想法吗?

在AskApple问答中;在地图上的一次会议上,我确认3D卫星只适用于某些地区。这是完全可以理解的,所以我想在不支持三维视图的位置以编程方式禁用三维功能。不幸的是,AskApple问答;A还表示,目前还没有一种方法来识别3D卫星在某个位置是否可用。我向苹果提交了一个增强建议,但目前还没有办法通过编程禁用3D。

最新更新