feat(destination): add a map point to the destination

This commit is contained in:
2024-11-29 12:24:29 +01:00
parent 93b17fcc4f
commit d5bada6793
3 changed files with 21 additions and 2 deletions

View File

@@ -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..<directions.count) { i in
if destination != nil {
Marker(item: destination!)
}
MapPolyline(directions[i].polyline)
.stroke(Defaults.routeColor[i], lineWidth: Defaults.routeWidth)
}
@@ -48,7 +56,7 @@ struct ContentView: View {
content: {
SearchView(
directions: $directions, stepLength: $stepLength,
locationManager: locationManager
locationManager: locationManager, destination: $destination
)
.ignoresSafeArea()
}
@@ -78,6 +86,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) {
viewModel.saveValue(value)

View File

@@ -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
}
}
}

View File

@@ -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)
}
}
}