Ich habe eine benutzerdefinierte Klasse, wo ich die Variable "Typ" hinzufügen kann, die diesen Typ unterscheidet, das ist die Option, das Symbol zu ändern, aber ich habe keine Ahnung, wo ich das Symbol ändern kann, ich habe versucht, in das Verfahren mapView zu tun, ohne ein Ergebnis Import UIKit zu bekommen Import Coredata Import MapKitBenutzerdefinierte eine Annotation Ansicht Bild Direferenten
class MKAnnotationCostum: NSObject, MKAnnotation{
var coordinate : CLLocationCoordinate2D
var title : String?
var subtitle : String?
var tipo:String?
var image: UIImage?
init (coordinate : CLLocationCoordinate2D , title : String , subtitle : String, tipo:String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
self.tipo = tipo
}
}
i bekommen möchte ein Bild direferent für tipo je
import UIKit
import MapKit
import CoreData
class ThreeViewController: UIViewController,MKMapViewDelegate {
@IBOutlet weak var myMap: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
//viewDidAppear(true)
myMap.delegate = self
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
let request = NSFetchRequest(entityName: "PUNTO")
if let results = try? context.executeFetchRequest(request) {
for resultado in results {
let latitud:CLLocationDegrees = Double(resultado.valueForKey("puntoLatitud") as! NSNumber)
let longitud:CLLocationDegrees = Double(resultado.valueForKey("puntoLongitud") as! NSNumber)
let lateDelta:CLLocationDegrees = 0.01
let longDelta:CLLocationDegrees = 0.01
let span: MKCoordinateSpan = MKCoordinateSpanMake(lateDelta, longDelta)
let location: CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitud,longitud)
let region:MKCoordinateRegion = MKCoordinateRegionMake(location, span)
myMap.setRegion(region, animated: true)
let pointAnnotation = MKAnnotationCostum(coordinate: location, title: resultado.valueForKey("puntoDireccion") as! String, subtitle: "Latitud: \(resultado.valueForKey("puntoLatitud")!), Longitud: \(resultado.valueForKey("puntoLongitud")!) ", tipo:resultado.valueForKey("clasId") as! String)
// pointAnnotation.coordinate = location
// pointAnnotation.title = String(resultado.valueForKey("puntoDireccion")!)
// pointAnnotation.subtitle = String("Latitud: \(resultado.valueForKey("puntoLatitud")!), Longitud: \(resultado.valueForKey("puntoLongitud")!) ")
print("color: \(pointAnnotation.tipo)")
myMap.addAnnotation(pointAnnotation)
//mapView(myMap, viewForAnnotation: pointAnnotation)
}
}
myMap.showsUserLocation = true
}
func mapView(mapaView: MKMapView, viewForAnnotation anotacion: MKAnnotation) -> MKAnnotationView? {
if !(anotacion is MKAnnotationCostum) {
let reusarId = "anotacion"
var anotacionView = mapaView.dequeueReusableAnnotationViewWithIdentifier(reusarId)
if anotacionView == nil {
anotacionView = MKAnnotationView(annotation: anotacion, reuseIdentifier: reusarId)
anotacionView!.canShowCallout = true
anotacionView!.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "Amarillo"))
}
else {
anotacionView!.annotation = anotacion
}
return anotacionView
}
let reusarId = "anotacion"
var anotacionView = mapaView.dequeueReusableAnnotationViewWithIdentifier(reusarId)
let costum = anotacion as! MKAnnotationCostum
if anotacionView == nil {
anotacionView = MKAnnotationView(annotation: costum, reuseIdentifier: reusarId)
//let costumView = anotacionView as! MKAnnotationCostum
anotacionView!.image = UIImage(named:"Amarillo")
anotacionView!.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "marca"))
anotacionView!.canShowCallout = true
}else {
anotacionView!.annotation = anotacion
}
return anotacionView
}
UIImage (genannt: "Amarillo") wird eingestellt bekommen ?? –
ja, aber alle haben das gleiche Bild –
Ich möchte je nach "tipo" ändern –