Skip to content

Commit

Permalink
Merge pull request #23 from DeveloperAcademy-POSTECH/fix/12-showing-b…
Browse files Browse the repository at this point in the history
…us-stop-location

[#12] 버스 루트 별 정류장 띄우기
  • Loading branch information
Minkyeong-Choi authored Oct 19, 2024
2 parents 9c3db01 + 45742de commit 15ddcef
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion TMT/TMT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@
D867396B2CA933CD00FFE8ED /* TMT */ = {
isa = PBXGroup;
children = (
5B6DA5B92CBE6F8700613ACB /* LocationManager.swift */,
D867396C2CA933CD00FFE8ED /* TMTApp.swift */,
D867396E2CA933CD00FFE8ED /* ContentView.swift */,
5B6DA5B72CBE551400613ACB /* MapView.swift */,
5B6DA5B92CBE6F8700613ACB /* LocationManager.swift */,
D844BCD82CC1472E0059E31F /* Utils */,
D8D377E72CBE95B80043D103 /* BusSearch */,
D8D377E42CBE548F0043D103 /* Resource */,
Expand Down
4 changes: 4 additions & 0 deletions TMT/TMT.xcodeproj/xcshareddata/xcschemes/TMT.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
ReferencedContainer = "container:TMT.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<LocationScenarioReference
identifier = "com.apple.dt.IDEFoundation.CurrentLocationScenarioIdentifier"
referenceType = "1">
</LocationScenarioReference>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
5 changes: 4 additions & 1 deletion TMT/TMT/BusSearch/BusSearchModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// Created by 김유빈 on 10/15/24.
//

struct BusStopInfo: Codable {
import Foundation

struct BusStopInfo: Codable, Identifiable {
var id = UUID()
var busNumber: String? // 노선명 (버스번호)
var busType: Int? // 버스 타입
var stopOrder: Int? // 순번
Expand Down
1 change: 0 additions & 1 deletion TMT/TMT/BusSearch/BusSearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ final class BusStopSearchViewModel: ObservableObject {
}
return false
}

fetchBusNumbersList()
}

Expand Down
4 changes: 2 additions & 2 deletions TMT/TMT/LocationManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// LocationManagerDelegate.swift
// LocationManager.swift
// TMT
//
// Created by Choi Minkyeong on 10/15/24.
Expand All @@ -11,7 +11,7 @@ import MapKit

class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
@Published var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
center: CLLocationCoordinate2D(latitude: 36.016082, longitude: 129.324605),
span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01)
)

Expand Down
55 changes: 38 additions & 17 deletions TMT/TMT/MapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,50 @@ import MapKit

struct MapView: View {
@StateObject private var locationManager = LocationManager()
@StateObject var busStopSearchViewModel = BusStopSearchViewModel()

var body: some View {
ZStack {
Map(coordinateRegion: $locationManager.region, showsUserLocation: true)
.edgesIgnoringSafeArea(.all)
VStack {
HStack {
Spacer()
Button {
locationManager.findCurrentLocation()
} label: {
ZStack {
Circle()
.frame(width: 40)
.tint(.white)
.shadow(radius: 5)
Image(systemName: "location.fill")
.font(.title)
.tint(.gray)
}
Map(coordinateRegion: $locationManager.region, showsUserLocation: true, annotationItems: busStopSearchViewModel.filteredBusStops) { stop in
MapAnnotation(coordinate: CLLocationCoordinate2D(latitude: Double(stop.xCoordinate ?? "") ?? 0, longitude: Double(stop.yCoordinate ?? "") ?? 0)) {
VStack {
RoundedRectangle(cornerRadius: 5)
.frame(width: 30, height: 30)
.foregroundStyle(.blue)
}
}
}
.edgesIgnoringSafeArea(.all)
VStack {
Button {
busStopSearchViewModel.searchBusStops(by: "207(기본)")
} label: {
Text("207번 버스")
.background(.white)
}

Button {
busStopSearchViewModel.searchBusStops(by: "306(기본)")
} label: {
Text("472번 버스")
.background(.white)
}

Spacer()
Button {
locationManager.findCurrentLocation()
} label: {
ZStack {
Circle()
.frame(width: 40)
.tint(.white)
.shadow(radius: 5)
Image(systemName: "location.fill")
.font(.title)
.tint(.gray)
}
}

}
.padding()
}
Expand Down

0 comments on commit 15ddcef

Please sign in to comment.