ios - Attempting to change MKAnnotation color within my code? -
so have set mkannotations
in mapview , it's working want to. experiment further , try change colors of pins, efficient way implement within following code:
override func viewdidappear(animated: bool) { var annotationquery = pfquery(classname: "post") currentloc = pfgeopoint(location: mapviewlocationmanager.location) //annotationquery.wherekey("location", neargeopoint: currentloc, withinmiles: 10) annotationquery.wherekeyexists("location") annotationquery.findobjectsinbackgroundwithblock { (points, error) -> void in if error == nil { // find succeeded. println("successful query annotations") // found objects let myposts = points as! [pfobject] post in myposts { let point = post["location"] as! pfgeopoint let annotation = mkpointannotation() annotation.coordinate = cllocationcoordinate2dmake(point.latitude, point.longitude) annotation.title = post["title"] as! string! annotation.subtitle = post["username"] as! string! func mapview(amapview: mkmapview!, viewforannotation annotation: mkannotation!) -> mkannotationview! { let reuseid = "pin" var pinview = amapview.dequeuereusableannotationviewwithidentifier(reuseid) as? mkpinannotationview println("pinview nil") pinview = mkpinannotationview(annotation: annotation, reuseidentifier: reuseid) pinview!.canshowcallout = true pinview!.animatesdrop = true pinview!.pincolor = .green return pinview } self.mapview.addannotation(annotation) } } else { // log details of failure println("error: \(error)") } }
i can't seem tackle on own though seem's simple enough. confused viewforannotation
method, gather seems need use it, nothing i'm trying working.
Comments
Post a Comment