Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ca97dfc
Design:iphone:: #32 Add SearchList
taek0622 Jun 1, 2023
e615a4e
Feat:sparkles:: #32 Add searching list visible
taek0622 Jun 1, 2023
0285b31
Style:art:: Modify isEdit variable
taek0622 Jun 1, 2023
af66783
Feat:sparkles:: Add AddressSearcher
taek0622 Jun 2, 2023
0cfb8ff
Chore:wrench:: Delete wrong bracket
taek0622 Jun 1, 2023
107bdda
Chore:wrench:: Modify searching variable
taek0622 Jun 2, 2023
864ad4c
Chore:wrench:: Delete legacy code
taek0622 Jun 1, 2023
c368e9e
Chore:wrench:: Delete Unused variable
taek0622 Jun 2, 2023
b251d44
Style:art:: Modify control flow
taek0622 Jun 1, 2023
ac6dc15
Feat:sparkles:: Add returning address coordinate
taek0622 Jun 2, 2023
4800120
Style:art:: Delete space
taek0622 Jun 1, 2023
ffd4e90
Feat:sparkles:: Add printing address coordinate
taek0622 Jun 2, 2023
0080a85
Style:art:: #32 Modify isEdit variable
taek0622 Jun 1, 2023
ef9b833
Feat:sparkles:: #32 Add AddressSearcher
taek0622 Jun 2, 2023
c3b868a
Chore:wrench:: #32 Modify searching variable
taek0622 Jun 2, 2023
aa730d5
Chore:wrench:: #32 Delete Unused variable
taek0622 Jun 2, 2023
2998860
Feat:sparkles:: #32 Add returning address coordinate
taek0622 Jun 2, 2023
445d066
Feat:sparkles:: #32 Add printing address coordinate
taek0622 Jun 2, 2023
7e24eee
Merge branches 'feat/32-search_mapkit' and 'feat/32-search_mapkit' of…
taek0622 Jun 2, 2023
44c6b04
Feature:sparkles:: #32 Add showing coordinate
taek0622 Jun 2, 2023
02c1f3a
Style:art:: Delete Unused comment
taek0622 Jun 2, 2023
28c70de
Chore:wrench:: #32 Modify searching variable
taek0622 Jun 2, 2023
498fc82
Chore:wrench:: #32 Modify Map Managing class name
taek0622 Jun 13, 2023
cd250ea
Chore:wrench:: #32 Modify loadAdressCoordinate
taek0622 Jun 13, 2023
add7d24
Style:art:: Add Space
taek0622 Jun 13, 2023
0906d0a
Chore:wrench:: #32 add animation
taek0622 Jun 13, 2023
e5e998e
Chore:wrench:: #32 Seperate searchedView
taek0622 Jun 13, 2023
0f2007e
Chore:wrench:: #32 Modify ObservedObject
taek0622 Jun 13, 2023
7efbd91
Chore:wrench:: #32 Modify navigationstack
taek0622 Jun 14, 2023
40806c2
Chore:wrench:: #21 Modify SearchedView Logic
taek0622 Jun 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Nav.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
26A1500D29083A1300BC7355 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A1500C29083A1300BC7355 /* ContentView.swift */; };
26A1500F29083A1400BC7355 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 26A1500E29083A1400BC7355 /* Assets.xcassets */; };
26A1501929083B7B00BC7355 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A1501829083B7B00BC7355 /* MapView.swift */; };
26A82ED82A29CCDE00C23407 /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A82ED72A29CCDE00C23407 /* LocationManager.swift */; };
CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */; };
CE2D8D3A29C59DF100E5C104 /* CategoryPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */; };
DCE7EBCF2A172C1E00644745 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE7EBCE2A172C1E00644745 /* Extensions.swift */; };
Expand All @@ -37,6 +38,7 @@
26A1500C29083A1300BC7355 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
26A1500E29083A1400BC7355 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
26A1501829083B7B00BC7355 /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
26A82ED72A29CCDE00C23407 /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryPicker.swift; sourceTree = "<group>"; };
DCE7EBCE2A172C1E00644745 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,6 +94,7 @@
26A1501029083A1400BC7355 /* Preview Content */,
CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */,
CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */,
26A82ED72A29CCDE00C23407 /* LocationManager.swift */,
);
path = Nav;
sourceTree = "<group>";
Expand Down Expand Up @@ -227,6 +230,7 @@
CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */,
26A1500D29083A1300BC7355 /* ContentView.swift in Sources */,
262C17C2290D090C00450E54 /* Font+.swift in Sources */,
26A82ED82A29CCDE00C23407 /* LocationManager.swift in Sources */,
262C17C6290E385E00450E54 /* Text+.swift in Sources */,
262C17C0290D06F700450E54 /* Color+.swift in Sources */,
FDFD7A6129289926001BE945 /* Bundle+Ext.swift in Sources */,
Expand Down
43 changes: 43 additions & 0 deletions Nav/LocationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// LocationManager.swift
// Nav
//
// Created by 김민택 on 2023/06/02.
//

import Combine
import Foundation
import MapKit
import SwiftUI

class LocationManager: NSObject, ObservableObject, MKLocalSearchCompleterDelegate {
@Published var searchQuery = ""
var completer: MKLocalSearchCompleter
@Published var completions: [MKLocalSearchCompletion] = []
var cancellable: AnyCancellable?

override init() {
completer = MKLocalSearchCompleter()
super.init()
cancellable = $searchQuery.assign(to: \.queryFragment, on: self.completer)
completer.delegate = self
}

func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
self.completions = completer.results
}

func loadAddressCoordinate(_ address: MKLocalSearchCompletion, completoinHandler: @escaping (MKCoordinateRegion) -> Void) {
let searchRequest = MKLocalSearch.Request(completion: address)
let search = MKLocalSearch(request: searchRequest)
search.start { response, error in
guard error == nil else { return }
guard let coordinate = response?.boundingRegion.center else { return }
guard let span = response?.boundingRegion.span else { return }

completoinHandler(MKCoordinateRegion(center: coordinate, span: span))
}
}
}

extension MKLocalSearchCompletion: Identifiable {}
137 changes: 39 additions & 98 deletions Nav/View/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,67 @@
import MapKit
import SwiftUI
struct MapView: View {
private var mockDatas: [MockDatum] = MockDatum.allData

@State var searchQueryString = ""
@StateObject var locationManager = LocationManager()

// 서울 좌표
@State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.5666791, longitude: 126.9782914), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
@State private var isLoggedIn: Bool = true
@State private var isClickedYes: Bool = false
@State private var isShowModal: Bool = false

private var mockDatas: [MockDatum] = MockDatum.allData

var body: some View {
NavigationView {
NavigationStack {
ZStack {
Map(coordinateRegion: $region,
showsUserLocation: false,
annotationItems: mockDatas){
annotationItems: mockDatas) {
data in MapMarker(coordinate: data.coordinate)
}

HStack {
Spacer()

VStack {
Button(action: {}) {
Image(systemName: "gearshape")
.circleButton(
iconColor: .navWhite,
iconWidth: 20,
iconHeight: 20,
buttonColor: .primaryRed,
buttonSize: 50,
shadowRadius: 4,
shadowY: 4
)
.shadow(radius: 4, y: 4)
}

NavigationLink {
ListView()
} label: {
Image(systemName: "list.bullet")
.circleButton(
iconColor: .navWhite,
iconWidth: 20,
iconHeight: 14.5,
buttonColor: .primaryRed,
buttonSize: 50,
shadowRadius: 4,
shadowY: 4
)
.shadow(radius: 4, y: 4)
}

Spacer()

Button {
if isLoggedIn {
isShowModal = true
} else {
isClickedYes = true
}
} label: {
Image(systemName: "plus")
.circleButton(
iconColor: .navWhite,
iconWidth: 17,
iconHeight: 16,
buttonColor: .primaryRed,
buttonSize: 50,
shadowRadius: 4,
shadowY: 4
)
.shadow(radius: 4, y: 4)
}
}
.padding(.trailing, 16)
.alert("로그인이 필요한 서비스입니다.",
isPresented: $isClickedYes,
actions: {
Button("취소", role: .cancel, action: {})
Button("로그인", role: .none, action: {})
},
message: {
Text("로그인을 하시면 모든 서비스를 이용하실 수 있습니다. 로그인 하시겠습니까?")
}
)
.sheet(isPresented: $isShowModal) {
NavigationView {
VStack {
PinCreationView()
}
.padding(16)
.navigationTitle("핀 추가")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
isShowModal = false
} label: {
Image(systemName: "xmark")
.foregroundColor(.black)
}
}
}
}
}
if locationManager.searchQuery != "" {
SearchedView(region: $region)
.environmentObject(locationManager)
}
}
.navigationTitle("NAV")
.searchable(
text: $searchQueryString,
text: $locationManager.searchQuery,
placement: .navigationBarDrawer,
prompt: "검색"
)
}
}

}

private struct SearchedView: View {
@EnvironmentObject var locationManager: LocationManager
@Binding var region: MKCoordinateRegion
@Environment(\.dismissSearch) private var dismissSearch

var body: some View {
List(locationManager.completions) { completion in
Button {
locationManager.loadAddressCoordinate(completion) { location in
withAnimation {
region = location
}
}
dismissSearch()
} label: {
VStack(alignment: .leading) {
Text(completion.title)
if completion.subtitle != "" {
Text(completion.subtitle)
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
}
}
}

struct MapView_Previews: PreviewProvider {
static var previews: some View {
MapView()
}
}
}