Dimitris Togias

add directions url

......@@ -25,6 +25,7 @@ class MapsViewController: UIViewController, MKMapViewDelegate {
// public
public var couponSet: swiftApi.CouponSetItemModel?
var merchantsArray:Array<swiftApi.MerchantModel> = []
var selectedMerchant: swiftApi.MerchantModel?
//
var loading: Bool = false
......@@ -112,6 +113,24 @@ class MapsViewController: UIViewController, MKMapViewDelegate {
@IBAction func directionsButtomAction(_ sender: Any) {
guard let lon = selectedMerchant?._longitude, let lat = selectedMerchant?._latitude else {
return
}
// guard your URL instances
guard let googleMapsUrl = URL(string: String(format: "https://www.google.com/maps/@%.6f,%.6f,6z", lat, lon)),
let appleMapsUrl = URL(string: String(format: "http://maps.apple.com/?ll=%.6f,%.6f", lat, lon)) else {
print("Error creating URLs")
return
}
// check if link can be opened with google maps.
guard UIApplication.shared.canOpenURL(googleMapsUrl) else {
UIApplication.shared.open(appleMapsUrl, options: [:], completionHandler: nil)
return
}
UIApplication.shared.open(googleMapsUrl, options: [:], completionHandler: nil)
}
private func loadMapPins() {
......@@ -122,6 +141,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate {
}
private func loadPinDetailsView(_ annotation: MerchantAnnotation) {
self.selectedMerchant = annotation.model
self.titleView.text = "INTERSPORT"
self.nameImageView.image = UIImage(named: "intersport")
self.nameView.text = "Intersport Χαλάνδρι"
......@@ -138,6 +159,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate {
}
private func hidePinDetailsView() {
self.selectedMerchant = nil
self.infoTopConstraint.constant = 0
UIView.animate(withDuration: 2.0) {
self.view.layoutIfNeeded()
......