Ich brauche deine Hilfe. Ich arbeite an einer App, die einige Orte in meiner Nähe zeigt. Es zeigt den Namen des Ortes und die Entfernung. Womit ich Probleme habe, ist ein Bild hinzuzufügen, so dass der Benutzer die Standortbeschreibung und ein Bild sehen kann. Wie kann ich es tun? Mein Code ist die folgende ...(Swift) Fügt meiner Annotation ein Callout hinzu
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
let locationManager = CLLocationManager()
struct Location {
let title: String
let latitude: Double
let longitude: Double
}
let locations = [
Location(title: "Saint Paul Hospital", latitude: 49.280524700, longitude: -123.128232600)
]
override func viewDidLoad() {
super.viewDidLoad()
mapita.showsUserLocation = true
for location in locations {
let annotation = MKPointAnnotation()
annotation.title = location.title
annotation.coordinate = CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
if let currentLocation = locationManager.location?.coordinate {
let locationMapPoint = MKMapPointForCoordinate(currentLocation)
let pinMapPoint = MKMapPointForCoordinate(annotation.coordinate)
let distance = MKMetersBetweenMapPoints(locationMapPoint, pinMapPoint)
if distance >= 0 && distance <= 4500000 {
let distancia: Double = round (distance/1000)
annotation.subtitle = "Dist. \(distancia) kilometros"
mapita.addAnnotation(annotation)
}
}
}
Dies ist, was ich bekomme. Was ich brauche, ist das Bild in die Callouts
setzen Ich würde mich über Ihre Hilfe Jungs freuen! Danke
ein UIImageView verwenden und es ist Bild – user1046037