I'm using Xcode 14.0 beta 3 (14A5270f) on macOS 13.0 beta 3 (22A5295h).
SwiftUI Map with annotationItems: and annotationContent: doesn't seem to work. No annotations show up on the map, either with MapMarker or MapAnnotation. I tried running the code below on the same macOS as well as iOS 16.0 beta 3 (20A5312g).
Is this a beta software bug or is there anything wrong with the code?
import SwiftUI
import MapKit
struct Place: Identifiable {
let id: String
let location: CLLocationCoordinate2D
init(id: String, latitude: CLLocationDegrees, longitude: CLLocationDegrees) {
self.id = id
self.location = CLLocationCoordinate2D(latitude: longitude, longitude: longitude)
}
}
struct ContentView: View {
@State private var mapCoordinateRegion: MKCoordinateRegion = .init(.world)
let places = [Place(id: "test", latitude: 37.3346917, longitude: -122.0111262)]
var body: some View {
Map(coordinateRegion: self.$mapCoordinateRegion, showsUserLocation: true, annotationItems: self.places) { place in
MapMarker(coordinate: place.location, tint: .blue)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}