MOSTLY WORKSSSSS!!!!!

This commit is contained in:
Max Hunt 2019-05-29 19:22:25 +01:00
parent c924c5cd39
commit b7d17a502d
2 changed files with 64 additions and 51 deletions

View File

@ -1,93 +1,111 @@
{ {
"images" : [ "images" : [
{ {
"idiom" : "iphone",
"size" : "20x20", "size" : "20x20",
"idiom": "iphone",
"filename" : "tLogo-20@2x.png",
"scale": "2x" "scale": "2x"
}, },
{ {
"idiom" : "iphone",
"size" : "20x20", "size" : "20x20",
"idiom": "iphone",
"filename" : "tLogo-20@3x.png",
"scale": "3x" "scale": "3x"
}, },
{ {
"idiom" : "iphone", "size" : "20x20",
"size" : "29x29", "idiom": "ipad",
"filename" : "tLogo-20.png",
"scale": "1x"
},
{
"size" : "20x20",
"idiom": "ipad",
"filename" : "tLogo-20@2x.png",
"scale": "2x" "scale": "2x"
}, },
{ {
"idiom" : "iphone",
"size" : "29x29", "size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone", "idiom" : "iphone",
"size" : "40x40", "filename" : "tLogo-29@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"size" : "29x29",
"idiom" : "iphone", "idiom" : "iphone",
"size" : "40x40", "filename" : "tLogo-29@3x.png",
"scale" : "3x" "scale" : "3x"
}, },
{ {
"size" : "40x40",
"idiom" : "iphone", "idiom" : "iphone",
"filename" : "tLogo-40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "tLogo-40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60", "size" : "60x60",
"idiom" : "iphone",
"filename" : "tLogo-60@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "iphone",
"size" : "60x60", "size" : "60x60",
"idiom" : "iphone",
"filename" : "tLogo-60@3x.png",
"scale" : "3x" "scale" : "3x"
}, },
{ {
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29", "size" : "29x29",
"idiom" : "ipad",
"filename" : "tLogo-29.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "ipad",
"size" : "29x29", "size" : "29x29",
"idiom" : "ipad",
"filename" : "tLogo-29@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "ipad",
"size" : "40x40", "size" : "40x40",
"idiom" : "ipad",
"filename" : "tLogo-40.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "ipad",
"size" : "40x40", "size" : "40x40",
"idiom" : "ipad",
"filename" : "tLogo-40@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "ipad",
"size" : "76x76", "size" : "76x76",
"idiom" : "ipad",
"filename" : "tLogo-76.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "ipad",
"size" : "76x76", "size" : "76x76",
"idiom" : "ipad",
"filename" : "tLogo-76@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "ipad",
"size" : "83.5x83.5", "size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "tLogo-83.5@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "ios-marketing",
"size" : "1024x1024", "size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "tLogo-1024.png",
"scale" : "1x" "scale" : "1x"
} }
], ],

View File

@ -53,13 +53,18 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
self.searchBarBg.layer.shadowColor = UIColor.black.cgColor searchBar.delegate = self
self.searchBarBg.layer.cornerRadius = 10 searchBarBg.layer.shadowColor = UIColor.black.cgColor
self.searchBarBg.layer.shadowOffset = CGSize(width: 5, height: 7) searchBarBg.layer.cornerRadius = 10
self.searchBarBg.layer.shadowRadius = 10 searchBarBg.layer.shadowOffset = CGSize(width: 5, height: 7)
self.searchBarBg.layer.shadowOpacity = 0.2 searchBarBg.layer.shadowRadius = 10
searchBarBg.layer.shadowOpacity = 0.2
locationManager.delegate = (self as! CLLocationManagerDelegate) mapView.delegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation() locationManager.startUpdatingLocation()
@ -105,27 +110,21 @@ class MainViewController: UIViewController, AVAudioPlayerDelegate {
} //END OF CLASS } //END OF CLASS
extension MainViewController: CLLocationManagerDelegate {
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let currentLocation = locations.first else { return } guard let currentLocation = locations.first else { return }
currentCoordinate = currentLocation.coordinate currentCoordinate = currentLocation.coordinate
mapView.userTrackingMode = .follow mapView.userTrackingMode = .follow
if startedNavigation == true { if startedNavigation == true {
StepLabel.text = "On step: \(stepCounter)"
let nextStep = steps[stepCounter] let nextStep = steps[stepCounter]
let nextCoord = CLLocation(latitude: nextStep.polyline.coordinate.latitude, longitude: nextStep.polyline.coordinate.longitude) let nextCoord = CLLocation(latitude: nextStep.polyline.coordinate.latitude, longitude: nextStep.polyline.coordinate.longitude)
distanceToNextCoord = currentLocation.distance(from: nextCoord) distanceToNextCoord = currentLocation.distance(from: nextCoord)
devonLbl.text = String(format: "Distance to next waypoint: %.2f meters", distanceToNextCoord)
a.text = String(format: "%.2f", previousDistanceToWaypoint)//"\(previousDistanceToWaypoint)"
b.text = String(format: "%.2f", distanceToNextCoord)//"\(distanceToNextCoord)"
if distanceToNextCoord < previousDistanceToWaypoint { if distanceToNextCoord < previousDistanceToWaypoint {
previousDistanceToWaypoint = currentLocation.distance(from: nextCoord) previousDistanceToWaypoint = currentLocation.distance(from: nextCoord)
} }
if distanceToNextCoord > previousDistanceToWaypoint + 10 { if distanceToNextCoord > previousDistanceToWaypoint + 10 {
devonLbl.text = String(format: "WRONG WAY (%.2f > %.2f)", distanceToNextCoord, previousDistanceToWaypoint+10)
previousDistanceToWaypoint = distanceToNextCoord - 5 previousDistanceToWaypoint = distanceToNextCoord - 5
playTurnArd() playTurnArd()
} }
@ -134,7 +133,6 @@ extension ViewController: CLLocationManagerDelegate {
if stepCounter < steps.count { if stepCounter < steps.count {
// let currentStep = steps[stepCounter] // let currentStep = steps[stepCounter]
let message = "\(steps[stepCounter-1].instructions)" let message = "\(steps[stepCounter-1].instructions)"
directionsLabel.text = message
let maneuverCommand = String(message.prefix(10)) let maneuverCommand = String(message.prefix(10))
switch (maneuverCommand) { switch (maneuverCommand) {
case "Turn right": case "Turn right":
@ -154,7 +152,6 @@ extension ViewController: CLLocationManagerDelegate {
default: default:
playErr() playErr()
currentStepLbl.text = "ERR: \(message)"
break; break;
} }
@ -162,13 +159,10 @@ extension ViewController: CLLocationManagerDelegate {
// speechSynthesizer.speak(speechUtterance) // speechSynthesizer.speak(speechUtterance)
previousDistanceToWaypoint = 1000 previousDistanceToWaypoint = 1000
} else { } else {
let message = "Arrived at destination"
directionsLabel.text = message
// let speechUtterance = AVSpeechUtterance(string: message) // let speechUtterance = AVSpeechUtterance(string: message)
// speechSynthesizer.speak(speechUtterance) // speechSynthesizer.speak(speechUtterance)
stepCounter = 0 stepCounter = 0
previousDistanceToWaypoint = 1000 previousDistanceToWaypoint = 1000
cancelView.isHidden = true
searchBar.isHidden = false searchBar.isHidden = false
// locationManager.monitoredRegions.forEach({ self.locationManager.stopMonitoring(for: $0) }) // locationManager.monitoredRegions.forEach({ self.locationManager.stopMonitoring(for: $0) })
@ -224,8 +218,9 @@ extension ViewController: CLLocationManagerDelegate {
extension ViewController: UISearchBarDelegate { extension MainViewController: UISearchBarDelegate {
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("Here2")
searchBar.endEditing(true) //HIDES LE KEYBOARD searchBar.endEditing(true) //HIDES LE KEYBOARD
let localSearchRequest = MKLocalSearch.Request() let localSearchRequest = MKLocalSearch.Request()
@ -243,7 +238,7 @@ extension ViewController: UISearchBarDelegate {
} }
extension ViewController: MKMapViewDelegate { extension MainViewController: MKMapViewDelegate {
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolyline { if overlay is MKPolyline {
let renderer = MKPolylineRenderer(overlay: overlay) let renderer = MKPolylineRenderer(overlay: overlay)