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

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

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.html
匿名

发表评论

匿名网友

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

确定