英文:
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()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论