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