diff --git a/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/UserInterfaceState.xcuserstate b/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/UserInterfaceState.xcuserstate index c53581d..7b9129d 100644 Binary files a/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/UserInterfaceState.xcuserstate and b/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 2c9226b..1f20758 100644 --- a/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/Musgravite.xcworkspace/xcuserdata/Luna.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -10,11 +10,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Musgravite/Controller/DetailViewController.swift" - timestampString = "564818490.101434" + timestampString = "564861121.219802" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "133" - endingLineNumber = "133" + startingLineNumber = "205" + endingLineNumber = "205" landmarkName = "getData(_:_:_:)" landmarkType = "7"> @@ -42,11 +42,11 @@ ignoreCount = "0" continueAfterRunningActions = "No" filePath = "Musgravite/Controller/DetailViewController.swift" - timestampString = "564818490.102037" + timestampString = "564861121.220378" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "134" - endingLineNumber = "134" + startingLineNumber = "206" + endingLineNumber = "206" landmarkName = "getData(_:_:_:)" landmarkType = "7"> diff --git a/Musgravite/Controller/DetailViewController.swift b/Musgravite/Controller/DetailViewController.swift index 58a62e2..63a4508 100644 --- a/Musgravite/Controller/DetailViewController.swift +++ b/Musgravite/Controller/DetailViewController.swift @@ -13,15 +13,14 @@ import SVProgressHUD import Alamofire import SwiftMessages import WatchConnectivity +import MapKit -class DetailViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, WCSessionDelegate{ +class DetailViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, WCSessionDelegate, MKMapViewDelegate, CLLocationManagerDelegate { + /* WCSessionDelegate */ func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {} - func sessionDidBecomeInactive(_ session: WCSession) {} - func sessionDidDeactivate(_ session: WCSession) {} - //Laboratory information var labInformation:JSON? var selectedElementURL:URL? @@ -36,11 +35,13 @@ class DetailViewController: UIViewController, UICollectionViewDelegate, UICollec public let selection = UISelectionFeedbackGenerator() //Static Elements + @IBOutlet weak var mapOutlet: MKMapView! @IBOutlet weak var locationOutlet: UILabel! @IBOutlet weak var descriptionOutlet: UITextView! @IBOutlet weak var bigTitleOutlet: UITextView! @IBOutlet weak var bigImageOutlet: UIImageView! @IBOutlet weak var gradientCategory: UIImageView! + //CollectionViews @IBOutlet weak var imagesCollectionView: UICollectionView! @IBOutlet weak var videoCollectionView: UICollectionView! @@ -48,6 +49,9 @@ class DetailViewController: UIViewController, UICollectionViewDelegate, UICollec @IBOutlet weak var button360: UIButton! @IBOutlet weak var button3D: UIButton! + // CLLocationManager + let locationManager = CLLocationManager() + @IBAction func SwapMode(_ sender: Any) { if(button3D.isHidden == true){ button3D.isHidden = false @@ -68,7 +72,73 @@ class DetailViewController: UIViewController, UICollectionViewDelegate, UICollec wcSession.delegate = self wcSession.activate() button3D.isHidden = true + /* MapKit Delegate */ + mapOutlet.delegate = self + mapOutlet.showsPointsOfInterest = true + mapOutlet.showsScale = true + mapOutlet.showsUserLocation = true + displayMapDirections() + } + + func displayMapDirections(){ + /* Request Location */ + locationManager.requestAlwaysAuthorization() + locationManager.requestWhenInUseAuthorization() + + if CLLocationManager.locationServicesEnabled() { + locationManager.delegate = self + locationManager.desiredAccuracy = kCLLocationAccuracyBest + locationManager.startUpdatingLocation() + } + + let sourceCoordinates = locationManager.location?.coordinate + let destinationCoordinates = CLLocationCoordinate2D(latitude: 19.2833333, longitude: -99.1352777777779) + let sourcePlacemark = MKPlacemark(coordinate: sourceCoordinates!) + let destinationPlacemark = MKPlacemark(coordinate: destinationCoordinates) + let sourceItem = MKMapItem(placemark: sourcePlacemark) + let destinationItem = MKMapItem(placemark: destinationPlacemark) + let directionRequest = MKDirections.Request() + directionRequest.source = sourceItem + directionRequest.destination = destinationItem + directionRequest.transportType = .walking + let directions = MKDirections(request: directionRequest) + directions.calculate(completionHandler: {response, error in + guard let response = response else { + if let error = error { + print("omg something went wrong") + } + return + } + + let route = response.routes[0] + self.mapOutlet.addOverlay(route.polyline, level: .aboveRoads) + let rekt = route.polyline.boundingMapRect + self.mapOutlet.setRegion(MKCoordinateRegion(rekt), animated: true) + }) + } + + func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { + let renderer = MKPolylineRenderer(overlay: overlay) + renderer.strokeColor = UIColor.blue + renderer.lineWidth = 5.0 + return renderer + } + + @IBAction func sendToAppleMaps(_ sender: Any) { + let sourceCoordinates = locationManager.location?.coordinate + let destinationCoordinates = CLLocationCoordinate2D(latitude: 19.2833333, longitude: -99.1352777777779) + let directionsURL = "http://maps.apple.com/?saddr=\(sourceCoordinates?.latitude ?? 0),\(sourceCoordinates?.longitude ?? 0)&daddr=\(destinationCoordinates.latitude),\(destinationCoordinates.longitude)" + guard let url = URL(string: directionsURL) else { + return + } + if #available(iOS 10.0, *) { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } else { + UIApplication.shared.openURL(url) + } } + + @IBAction func sendToWatch(_ sender: Any) { sendLabInformation(labInformation!) } @@ -123,6 +193,8 @@ class DetailViewController: UIViewController, UICollectionViewDelegate, UICollec bigTitleOutlet.text = labInformation!["nombre"].stringValue /* To be changed once this information is available */ bigImageOutlet.sd_setImage(with: URL(string: labInformation!["PosterImage"].stringValue),placeholderImage: UIImage(named: "grad0")) + /* Create map value */ + } /* Downloads the required data from an URL */ diff --git a/Musgravite/Info.plist b/Musgravite/Info.plist index c398577..2c887b9 100644 --- a/Musgravite/Info.plist +++ b/Musgravite/Info.plist @@ -2,6 +2,12 @@ + NSLocationUsageDescription + $(PRODUCT_NAME) desea saber tu localización + NSLocationWhenInUseUsageDescription + $(PRODUCT_NAME) desea saber tu localización + NSLocationAlwaysUsageDescription + $(PRODUCT_NAME) desea saber tu localización CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleExecutable @@ -30,7 +36,7 @@ NSCameraUsageDescription $(PRODUCT_NAME) desea usar tu cámara para mostrar mundos virtuales. NSLocationAlwaysAndWhenInUseUsageDescription - $(PRODUCT_NAME) desea saber tu localización + $(PRODUCT_NAME) desea saber tu localización incluso cuando la aplicacion no este en uso. NSPhotoLibraryAddUsageDescription $(PRODUCT_NAME) desea acceder a tu carrete para escoger una imagen UILaunchStoryboardName diff --git a/Musgravite/View/Base.lproj/Main.storyboard b/Musgravite/View/Base.lproj/Main.storyboard index 59f762e..0fffde4 100644 --- a/Musgravite/View/Base.lproj/Main.storyboard +++ b/Musgravite/View/Base.lproj/Main.storyboard @@ -492,14 +492,14 @@ - + - + - + @@ -798,6 +798,9 @@ + + + @@ -818,10 +821,20 @@ + - + @@ -843,7 +856,7 @@ - + @@ -852,6 +865,7 @@ +