Showing
1 changed file
with
23 additions
and
0 deletions
... | @@ -25,6 +25,7 @@ class MapsViewController: UIViewController, MKMapViewDelegate { | ... | @@ -25,6 +25,7 @@ class MapsViewController: UIViewController, MKMapViewDelegate { |
25 | // public | 25 | // public |
26 | public var couponSet: swiftApi.CouponSetItemModel? | 26 | public var couponSet: swiftApi.CouponSetItemModel? |
27 | var merchantsArray:Array<swiftApi.MerchantModel> = [] | 27 | var merchantsArray:Array<swiftApi.MerchantModel> = [] |
28 | + var selectedMerchant: swiftApi.MerchantModel? | ||
28 | 29 | ||
29 | // | 30 | // |
30 | var loading: Bool = false | 31 | var loading: Bool = false |
... | @@ -112,6 +113,24 @@ class MapsViewController: UIViewController, MKMapViewDelegate { | ... | @@ -112,6 +113,24 @@ class MapsViewController: UIViewController, MKMapViewDelegate { |
112 | 113 | ||
113 | @IBAction func directionsButtomAction(_ sender: Any) { | 114 | @IBAction func directionsButtomAction(_ sender: Any) { |
114 | 115 | ||
116 | + guard let lon = selectedMerchant?._longitude, let lat = selectedMerchant?._latitude else { | ||
117 | + return | ||
118 | + } | ||
119 | + | ||
120 | + // guard your URL instances | ||
121 | + guard let googleMapsUrl = URL(string: String(format: "https://www.google.com/maps/@%.6f,%.6f,6z", lat, lon)), | ||
122 | + let appleMapsUrl = URL(string: String(format: "http://maps.apple.com/?ll=%.6f,%.6f", lat, lon)) else { | ||
123 | + print("Error creating URLs") | ||
124 | + return | ||
125 | + } | ||
126 | + | ||
127 | + // check if link can be opened with google maps. | ||
128 | + guard UIApplication.shared.canOpenURL(googleMapsUrl) else { | ||
129 | + UIApplication.shared.open(appleMapsUrl, options: [:], completionHandler: nil) | ||
130 | + return | ||
131 | + } | ||
132 | + | ||
133 | + UIApplication.shared.open(googleMapsUrl, options: [:], completionHandler: nil) | ||
115 | } | 134 | } |
116 | 135 | ||
117 | private func loadMapPins() { | 136 | private func loadMapPins() { |
... | @@ -122,6 +141,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate { | ... | @@ -122,6 +141,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate { |
122 | } | 141 | } |
123 | 142 | ||
124 | private func loadPinDetailsView(_ annotation: MerchantAnnotation) { | 143 | private func loadPinDetailsView(_ annotation: MerchantAnnotation) { |
144 | + self.selectedMerchant = annotation.model | ||
145 | + | ||
125 | self.titleView.text = "INTERSPORT" | 146 | self.titleView.text = "INTERSPORT" |
126 | self.nameImageView.image = UIImage(named: "intersport") | 147 | self.nameImageView.image = UIImage(named: "intersport") |
127 | self.nameView.text = "Intersport Χαλάνδρι" | 148 | self.nameView.text = "Intersport Χαλάνδρι" |
... | @@ -138,6 +159,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate { | ... | @@ -138,6 +159,8 @@ class MapsViewController: UIViewController, MKMapViewDelegate { |
138 | } | 159 | } |
139 | 160 | ||
140 | private func hidePinDetailsView() { | 161 | private func hidePinDetailsView() { |
162 | + self.selectedMerchant = nil | ||
163 | + | ||
141 | self.infoTopConstraint.constant = 0 | 164 | self.infoTopConstraint.constant = 0 |
142 | UIView.animate(withDuration: 2.0) { | 165 | UIView.animate(withDuration: 2.0) { |
143 | self.view.layoutIfNeeded() | 166 | self.view.layoutIfNeeded() | ... | ... |
-
Please register or login to post a comment