feat(destination): add a map point to the destination
This commit is contained in:
		| @@ -18,6 +18,9 @@ struct ContentView: View { | |||||||
|     @State private var position = MapCameraPosition.automatic |     @State private var position = MapCameraPosition.automatic | ||||||
|     @State private var showSearch: Bool = true |     @State private var showSearch: Bool = true | ||||||
|     @State private var directions: [MKRoute] = [] |     @State private var directions: [MKRoute] = [] | ||||||
|  |     @State private var destination: MKMapItem? | ||||||
|  |  | ||||||
|  |      | ||||||
|     @State var healthKitAccess = false |     @State var healthKitAccess = false | ||||||
|     @State var stepLength: Double? |     @State var stepLength: Double? | ||||||
|  |  | ||||||
| @@ -32,6 +35,8 @@ struct ContentView: View { | |||||||
|     // show how long does the route take with said walking speed |     // 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:/) |     // Add favorite locations - like home, work, etc (probably should be stored in core data tho:/) | ||||||
|      |      | ||||||
|  |     // FIX: search is bad lol | ||||||
|  |  | ||||||
|      |      | ||||||
|     // How to speed up? |     // How to speed up? | ||||||
|     // calculate only the distance between the start and end instead of getting directions for everything |     // calculate only the distance between the start and end instead of getting directions for everything | ||||||
| @@ -39,6 +44,9 @@ struct ContentView: View { | |||||||
|     var body: some View { |     var body: some View { | ||||||
|         Map(position: $position) { |         Map(position: $position) { | ||||||
|             ForEach(0..<directions.count) { i in |             ForEach(0..<directions.count) { i in | ||||||
|  |                 if destination != nil { | ||||||
|  |                     Marker(item: destination!) | ||||||
|  |                 } | ||||||
|                 MapPolyline(directions[i].polyline) |                 MapPolyline(directions[i].polyline) | ||||||
|                     .stroke(Defaults.routeColor[i], lineWidth: Defaults.routeWidth) |                     .stroke(Defaults.routeColor[i], lineWidth: Defaults.routeWidth) | ||||||
|             } |             } | ||||||
| @@ -48,7 +56,7 @@ struct ContentView: View { | |||||||
|             content: { |             content: { | ||||||
|                 SearchView( |                 SearchView( | ||||||
|                     directions: $directions, stepLength: $stepLength, |                     directions: $directions, stepLength: $stepLength, | ||||||
|                     locationManager: locationManager |                     locationManager: locationManager, destination: $destination | ||||||
|                 ) |                 ) | ||||||
|                 .ignoresSafeArea() |                 .ignoresSafeArea() | ||||||
|             } |             } | ||||||
| @@ -79,6 +87,14 @@ struct ContentView: View { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     func getLastPointFor(route: MKRoute) -> CLLocationCoordinate2D? { | ||||||
|  |         let pointCount =  route.polyline.pointCount | ||||||
|  |         if pointCount > 0 { | ||||||
|  |             return route.polyline.points()[pointCount - 1].coordinate | ||||||
|  |         } | ||||||
|  |         return nil | ||||||
|  |     } | ||||||
|  |  | ||||||
|     func save(value: String) { |     func save(value: String) { | ||||||
|         viewModel.saveValue(value) |         viewModel.saveValue(value) | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ struct SearchItemView: View { | |||||||
|     @Binding var stepLength: Double? |     @Binding var stepLength: Double? | ||||||
|     @Binding var showSteps: Bool |     @Binding var showSteps: Bool | ||||||
|     @State var localDirections: [MKRoute] = [] |     @State var localDirections: [MKRoute] = [] | ||||||
|  |     @Binding var destination: MKMapItem? | ||||||
|  |  | ||||||
|     var body: some View { |     var body: some View { | ||||||
|  |  | ||||||
| @@ -108,6 +109,7 @@ struct SearchItemView: View { | |||||||
|             } |             } | ||||||
|             self.localDirections = response.routes |             self.localDirections = response.routes | ||||||
|             self.distance = response.routes.first?.distance |             self.distance = response.routes.first?.distance | ||||||
|  |             self.destination = location | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ struct SearchView: View { | |||||||
|     @Binding var stepLength: Double? |     @Binding var stepLength: Double? | ||||||
|     @State var showSteps = true |     @State var showSteps = true | ||||||
|     var locationManager: LocationManager |     var locationManager: LocationManager | ||||||
|  |     @Binding var destination: MKMapItem? | ||||||
|  |  | ||||||
|     var body: some View { |     var body: some View { | ||||||
|         VStack { |         VStack { | ||||||
| @@ -50,7 +51,7 @@ struct SearchView: View { | |||||||
|                 ForEach(self.locations, id: \.identifier) { location in |                 ForEach(self.locations, id: \.identifier) { location in | ||||||
|                     SearchItemView( |                     SearchItemView( | ||||||
|                         location: location, directions: $directions, stepLength: $stepLength, |                         location: location, directions: $directions, stepLength: $stepLength, | ||||||
|                         showSteps: $showSteps) |                         showSteps: $showSteps, destination: $destination) | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user