diff --git a/StepMap/ContentView.swift b/StepMap/ContentView.swift index 98a9ac8..3c40560 100644 --- a/StepMap/ContentView.swift +++ b/StepMap/ContentView.swift @@ -18,6 +18,9 @@ struct ContentView: View { @State private var position = MapCameraPosition.automatic @State private var showSearch: Bool = true @State private var directions: [MKRoute] = [] + @State private var destination: MKMapItem? + + @State var healthKitAccess = false @State var stepLength: Double? @@ -31,6 +34,8 @@ struct ContentView: View { // Get walkingSpeed // show how long does the route take with said walking speed // Add favorite locations - like home, work, etc (probably should be stored in core data tho:/) + + // FIX: search is bad lol // How to speed up? @@ -39,6 +44,9 @@ struct ContentView: View { var body: some View { Map(position: $position) { ForEach(0.. CLLocationCoordinate2D? { + let pointCount = route.polyline.pointCount + if pointCount > 0 { + return route.polyline.points()[pointCount - 1].coordinate + } + return nil + } func save(value: String) { viewModel.saveValue(value) diff --git a/StepMap/SearchItemView.swift b/StepMap/SearchItemView.swift index c02dad3..9f9d112 100644 --- a/StepMap/SearchItemView.swift +++ b/StepMap/SearchItemView.swift @@ -17,6 +17,7 @@ struct SearchItemView: View { @Binding var stepLength: Double? @Binding var showSteps: Bool @State var localDirections: [MKRoute] = [] + @Binding var destination: MKMapItem? var body: some View { @@ -108,6 +109,7 @@ struct SearchItemView: View { } self.localDirections = response.routes self.distance = response.routes.first?.distance + self.destination = location } } } diff --git a/StepMap/SearchView.swift b/StepMap/SearchView.swift index 76e0edd..2c1e174 100644 --- a/StepMap/SearchView.swift +++ b/StepMap/SearchView.swift @@ -15,6 +15,7 @@ struct SearchView: View { @Binding var stepLength: Double? @State var showSteps = true var locationManager: LocationManager + @Binding var destination: MKMapItem? var body: some View { VStack { @@ -50,7 +51,7 @@ struct SearchView: View { ForEach(self.locations, id: \.identifier) { location in SearchItemView( location: location, directions: $directions, stepLength: $stepLength, - showSteps: $showSteps) + showSteps: $showSteps, destination: $destination) } } }