Im trying to get longitude and latitude from struct gService and set it on a Map.
But can't initialize @State var region
, because of error "Cannot use instance member 'service' within property initializer; property initializers run before 'self' is available" on service.latitude
and service.longitude
struct DetailCardView: View {
let service: gService
@State var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: service.latitude, longitude: service.longitude), span: MKCoordinateSpan(latitudeDelta: 0.0033, longitudeDelta: 0.0033))
var body: some View {
Map(coordinateRegion: $region, annotationItems: [MapPoint(coordinates: CLLocationCoordinate2D(latitude: service.latitude, longitude: service.longitude))]) { location in
MapAnnotation(coordinate: location.coordinates) {
Circle()
.stroke(.red, lineWidth: 3)
.frame(width: 50, height: 50, alignment: .center)
}
}
I googled this problem, but there were different cases.