I hope my question is clear, I am beginner in apple map kit
how to insert UIbutton instate of location pins
I have this code:
witch is shows a regular pin shape.
// maping 2
var fromLatD:Double = Double(fromLat)!
var fromLngD:Double = Double(fromLng)!
var toLatD:Double = Double(toLat)!
var toLngD:Double = Double(toLng)!
// 1.
mapView.delegate = self
// 2.
let sourceLocation = CLLocationCoordinate2D(latitude: fromLatD, longitude: fromLngD)
let destinationLocation = CLLocationCoordinate2D(latitude: toLatD, longitude: toLngD)
// 3.
let sourcePlacemark = MKPlacemark(coordinate: sourceLocation, addressDictionary: nil)
let destinationPlacemark = MKPlacemark(coordinate: destinationLocation, addressDictionary: nil)
// 4.
let sourceMapItem = MKMapItem(placemark: sourcePlacemark)
let destinationMapItem = MKMapItem(placemark: destinationPlacemark)
// 5.
let sourceAnnotation = MKPointAnnotation()
sourceAnnotation.title = fromname
if let location = sourcePlacemark.location {
sourceAnnotation.coordinate = location.coordinate
}
let destinationAnnotation = MKPointAnnotation()
destinationAnnotation.title = toname
if let location = destinationPlacemark.location {
destinationAnnotation.coordinate = location.coordinate
}
// 6.
self.mapView.showAnnotations([sourceAnnotation,destinationAnnotation], animated: true )
mapView.frame = CGRect (x: 0, y: 90, width: SW, height: 250)
view.addSubview(mapView)
// end map
i want to change this regular shape by UIbutton.
how can i do that ?
i want to change this
let destinationAnnotation = MKPointAnnotation()
destinationAnnotation.title = toname
if let location = destinationPlacemark.location {
destinationAnnotation.coordinate = location.coordinate
}
to custom UIbutton
like this
let mapfrom = UIButton()
mapfrom.frame = CGRect (x: 16, y: 5 , width: SW - 173, height: 45)
mapfrom.backgroundColor = UIColor.init(red: 250/255, green: 250/255, blue: 250/255, alpha: 1)
mapfrom.layer.borderColor = UIColor.init(red: 0, green: 151/255, blue: 255/255, alpha: 1).cgColor
mapfrom.layer.borderWidth = 1;
mapfrom.layer.cornerRadius = 10.0;
mapfrom.setTitle(NSLocalizedString("From:", comment: "") + " " + iconetype + " " + fromname,for: .normal)
mapfrom.setTitleColor(UIColor.init(red: 0, green: 151/255, blue: 255/255, alpha: 1), for: .normal)
mapfrom.layer.masksToBounds = true
mapfrom.layer.cornerRadius = 10
mapfrom.addTarget(self, action: #selector(openmapfrom), for: .touchUpInside)
view.addSubview(mapfrom)
i hope my question is clear ?