annotations - Users location (blue dot) keeps turning into red pin -
i have users location blue dot while having pins on mapview. pins have annotation has info button. can blue dot users location , enable pins have annotation such title subtitle. when go add info button red pins users location (blue dot) turns red pin.
i can't seem spot i'm going wrong. has last function because function puts info button onto annotation. selects users current location , turns pin reason :(
class gettothestart: uiviewcontroller, mkmapviewdelegate, cllocationmanagerdelegate { @iboutlet weak var mapview: mkmapview! let mylocmgr = cllocationmanager() override func viewdidload() { super.viewdidload() mylocmgr.desiredaccuracy = kcllocationaccuracybest mylocmgr.requestwheninuseauthorization() mylocmgr.startupdatinglocation() mylocmgr.delegate = self mapview.delegate = self var zoo = cllocationcoordinate2dmake(53.3562, -6.3053) var zoopin = mkpointannotation() zoopin.coordinate = zoo zoopin.title = "dublin zoo" zoopin.subtitle = "hello zoo" mapview.addannotation(zoopin) } func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) { // recient coordinate let mycoor = locations[locations.count - 1] //get lat & long let mylat = mycoor.coordinate.latitude let mylong = mycoor.coordinate.longitude let mycoor2d = cllocationcoordinate2d(latitude: mylat, longitude: mylong) //set span let mylatdelta = 0.05 let mylongdelta = 0.05 let myspan = mkcoordinatespan(latitudedelta: mylatdelta, longitudedelta: mylongdelta) let myregion = mkcoordinateregion(center: mycoor2d, span: myspan) self.mapview.showsuserlocation = true } func mapview(mapview: mkmapview, viewforannotation annotation: mkannotation) -> mkannotationview? { let reuseidentifier = "pin" var pin = mapview.dequeuereusableannotationviewwithidentifier(reuseidentifier) as? mkpinannotationview if pin == nil { pin = mkpinannotationview(annotation: annotation, reuseidentifier: reuseidentifier) pin!.pincolor = .red pin!.canshowcallout = true pin!.rightcalloutaccessoryview = uibutton(type: .detaildisclosure) } else { pin!.annotation = annotation } return pin }
viewforannotation delegate method called annotation on map including userlocation.
so check , return nil shown below...
func mapview(mapview: mkmapview, viewforannotation annotation: mkannotation) -> mkannotationview? { if annotation mkuserlocation { //return nil map view draws "blue dot" standard user location return nil } let reuseidentifier = "pin" var pin = mapview.dequeuereusableannotationviewwithidentifier(reuseidentifier) as? mkpinannotationview if pin == nil { pin = mkpinannotationview(annotation: annotation, reuseidentifier: reuseidentifier) pin!.pincolor = .red pin!.canshowcallout = true pin!.rightcalloutaccessoryview = uibutton(type: .detaildisclosure) } else { pin!.annotation = annotation } return pin }
Comments
Post a Comment