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 showSearch: Bool = true
|
||||
@State private var directions: [MKRoute] = []
|
||||
@State private var destination: MKMapItem?
|
||||
|
||||
|
||||
@State var healthKitAccess = false
|
||||
@State var stepLength: Double?
|
||||
|
||||
@@ -32,6 +35,8 @@ struct ContentView: View {
|
||||
// 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?
|
||||
// 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 {
|
||||
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()
|
||||
}
|
||||
@@ -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) {
|
||||
viewModel.saveValue(value)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user