From 1057bad23a63cb14f06f89554cb47912c708816b Mon Sep 17 00:00:00 2001 From: oliverhnat Date: Mon, 25 Nov 2024 17:31:36 +0100 Subject: [PATCH] feat(location): enable user location input --- StepMap.xcodeproj/project.pbxproj | 4 +++ StepMap/ContentView.swift | 32 ++++++++++++++--- StepMap/LocationManager.swift | 57 +++++++++++++++++++++++++++++++ StepMap/SearchItemView.swift | 8 ++--- StepMap/SearchView.swift | 33 ++++-------------- 5 files changed, 98 insertions(+), 36 deletions(-) create mode 100644 StepMap/LocationManager.swift diff --git a/StepMap.xcodeproj/project.pbxproj b/StepMap.xcodeproj/project.pbxproj index c7764c3..fc5a1ac 100644 --- a/StepMap.xcodeproj/project.pbxproj +++ b/StepMap.xcodeproj/project.pbxproj @@ -255,6 +255,8 @@ DEVELOPMENT_TEAM = SSJBLTMP95; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "We need to access your location to set starting point of your route"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "We need to access your location to set starting point of your route"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; @@ -284,6 +286,8 @@ DEVELOPMENT_TEAM = SSJBLTMP95; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSLocationAlwaysAndWhenInUseUsageDescription = "We need to access your location to set starting point of your route"; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "We need to access your location to set starting point of your route"; INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UILaunchScreen_Generation = YES; diff --git a/StepMap/ContentView.swift b/StepMap/ContentView.swift index 3fb802e..1e0afed 100644 --- a/StepMap/ContentView.swift +++ b/StepMap/ContentView.swift @@ -5,11 +5,13 @@ // Created by Oliver Hnát on 23.11.2024. // +import CoreLocation import MapKit import SwiftUI struct ContentView: View { @ObservedObject var viewModel = ViewModel() + @StateObject var locationManager = LocationManager() @State private var position = MapCameraPosition.automatic @State private var showSearch: Bool = true @@ -25,17 +27,37 @@ struct ContentView: View { var body: some View { Map(position: $position) { - ForEach(0..