I am trying to render more than one string information in my point selected with Swift UI.
So far, I am rendering a map with a trip and different stops in it.
When the user selects one of them, I want to show: the price, the passanger and the time.
Is it possible to render more than one string using MKPointAnnotation?
This is the example:
import MapKit
import SwiftUI
class MapViewModel: ObservableObject {
[.......]
for stop in trip.stops {
guard let stopPoint = stop.point else { continue }
let stopAnnotation = MKPointAnnotation()
stopAnnotation.coordinate = CLLocationCoordinate2D(latitude: stopPoint.latitude, longitude: stopPoint.longitude)
// HERE I WANT TO SHOW MORE THAN ONE STRING
if let stopInfo = self.stopInfo {
stopAnnotation.title = "Passenger: (stopInfo.userName)n" + " Price: (stopInfo.price)"
} else {
stopAnnotation.title = "Passenger: UnknownnPrice: Unknown"
}
if let stopInfo = self.stopInfo {
stopAnnotation.title = " Price: (stopInfo.price)"
} else {
stopAnnotation.title = "Passenger: UnknownnPrice: Unknown"
}
newAnnotations.append(stopAnnotation)
}
annotations = newAnnotations
}
func updateStopInfo(stopInfo: StopInfo){
self.stopInfo = stopInfo
print("updateStopInfo called")
}
}
class StopAnnotation: MKPointAnnotation {
var stop: StopInfo
init(stop: StopInfo) {
self.stop = stop
super.init()
self.coordinate = CLLocationCoordinate2D(latitude: stop.point.latitude, longitude: stop.point.longitude)
}
}