`Map(coordinateRegion: , showsUserLocation: )` 在iOS 17.0中已被弃用。

huangapple go评论150阅读模式
英文:

Map(coordinateRegion: , showsUserLocation: ) deprecated in iOS 17.0

问题

有没有替代这个调用的想法?它以前非常有用,现在在iOS 17.0中已被弃用。

原代码部分:

Map(coordinateRegion: $viewModel.region, showsUserLocation: true)

这是通过以下方式提供的:

enum MapDetails {
     static let startingLocation = CLLocationCoordinate2D(latitude: GlobalVariables.latitude, longitude: GlobalVariables.longitude)
     static let defaultSpan      = MKCoordinateSpan(latitudeDelta: GlobalVariables.span, longitudeDelta: GlobalVariables.span)
}

final class LocationViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {

var locationManager:  CLLocationManager?
@Published var region = MKCoordinateRegion(center: MapDetails.startingLocation, span: MapDetails.defaultSpan)

...

黄色警告是:

'init(coordinateRegion:interactionModes:showsUserLocation:userTrackingMode:)' 在iOS 17.0中已被弃用:使用接受MapContentBuilder的Map初始化程序。

是否有明显的替代方案我可能忽视了?

英文:

Any ideas of how to replace this call? It was blindingly useful and has now been deprecated in iOS 17.0.

Map(coordinateRegion: $viewModel.region, showsUserLocation: true)

This was being fed via:

enum MapDetails {
     static let startingLocation = CLLocationCoordinate2D(latitude: GlobalVariables.latitude, longitude: GlobalVariables.longitude)
     static let defaultSpan      = MKCoordinateSpan(latitudeDelta: GlobalVariables.span, longitudeDelta: GlobalVariables.span)
}

final class LocationViewModel: NSObject, ObservableObject, CLLocationManagerDelegate {

var locationManager:  CLLocationManager?
@Published var region = MKCoordinateRegion(center: MapDetails.startingLocation, span: MapDetails.defaultSpan)

...

The yellow warning is:

> 'init(coordinateRegion:interactionModes:showsUserLocation:userTrackingMode:)' was deprecated in iOS 17.0: Use Map initializers that take a MapContentBuilder instead.

Is there an obvious replacement that I have overlooked?

答案1

得分: 1

使用init(position:bounds:interactionModes:scope:content:)初始化方法。这个方法需要一个NapCameraPosition的绑定,因此你应该相应地更改视图模型中的类型。

请注意,你可以使用MapCameraPosition.region(_:)MKCoordinateRegion创建一个MapCameraPosition

要显示用户的位置,使用UserAnnotation

Map(position: $viewModel.region) {
    UserAnnotation()
}
英文:

Use the init(position:bounds:interactionModes:scope:content:) initialiser instead. This takes a binding of NapCameraPosition, so you should change the type in the view model accordingly.

Note that you can create a MapCameraPosition from a MKCoordinateRegion by using MapCameraPosition.region(_:).

To show the user's position, use a UserAnnotation

Map(position: $viewModel.region) {
    UserAnnotation()
}

huangapple
  • 本文由 发表于 2023年8月9日 14:42:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865201-2.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定