Skip to content

Commit

Permalink
feat/#11
Browse files Browse the repository at this point in the history
Maps에 Modal 연결-머문시간, 클로버 갯수 업데이트
  • Loading branch information
EvelynMacbookPro committed Aug 21, 2024
1 parent 391f4ae commit 0d1313e
Show file tree
Hide file tree
Showing 13 changed files with 478 additions and 418 deletions.
52 changes: 52 additions & 0 deletions AnnotationHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// AnnotationHelpers.swift
// MC2Maps
//
// Created by Evelyn Hong on 8/21/24.
//

import Foundation
import CoreLocation

// MARK: - Annotation Management

extension MapsView {
// MARK: 어노테이션을 추가하는 함수
func addAnnotation() {
guard annotations.count < maxAnnotations, let baseLocation = baseLocation else {
return // 최대 어노테이션 수에 도달하면 추가하지 않음
}

specialAnnotationCounter += 1
let isSpecial = (specialAnnotationCounter % 4 == 0)
// 4로 나눈 나머지가 0일 때 isSpecial이 true, 나머지는 false

let index = annotations.count
let row = index / gridSize
let column = index % gridSize

// 그리드 셀 내에서 무작위 오프셋 계산
let offsetLat = (Double(row) + Double.random(in: 0...1)) * 0.0001
let offsetLon = (Double(column) + Double.random(in: 0...1)) * 0.0001

// 변동 위치 계산
let newCoordinate = calculateOffsetCoordinate(base: baseLocation, offsetLat: offsetLat, offsetLon: offsetLon)
let newAnnotation = AnnotationItem(coordinate: newCoordinate, isSpecial: isSpecial)

// 새로운 어노테이션 추가
annotations.append(newAnnotation)
}

// MARK: 계산된 새로운 좌표 반환
func calculateOffsetCoordinate(base: CLLocationCoordinate2D, offsetLat: Double, offsetLon: Double) -> CLLocationCoordinate2D {
let newLatitude = base.latitude + offsetLat
let newLongitude = base.longitude + offsetLon
return CLLocationCoordinate2D(latitude: newLatitude, longitude: newLongitude)
}

// MARK: 클로버 수를 업데이트하는 함수
func updateCloverCounts() {
cloverCounts.threeLeaf = annotations.filter { !$0.isSpecial }.count
cloverCounts.fourLeaf = annotations.filter { $0.isSpecial }.count
}
}
26 changes: 26 additions & 0 deletions AnnotationItem.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// AnnotationItem.swift
// MC2Maps
//
// Created by Evelyn Hong on 8/21/24.
//

// AnnotationItem.swift
// MC2Maps
//
// Created by donghwan on 8/21/24.
//

import Foundation
import CoreLocation

//MARK: 커스텀 어노테이션 구조체 생성
struct AnnotationItem: Identifiable, Equatable {
let id = UUID()
var coordinate: CLLocationCoordinate2D
var isSpecial: Bool

static func == (lhs: AnnotationItem, rhs: AnnotationItem) -> Bool {
return lhs.id == rhs.id // 여기서는 ID가 같으면 같은 어노테이션으로 간주
}
}
21 changes: 21 additions & 0 deletions AnnotationModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AnnotationModels.swift
// MC2Maps
//
// Created by Evelyn Hong on 8/21/24.
//

import Foundation
import CoreLocation

// MARK: - AnnotationItem

struct AnnotationItem: Identifiable, Equatable {
let id = UUID()
var coordinate: CLLocationCoordinate2D
var isSpecial: Bool

static func == (lhs: AnnotationItem, rhs: AnnotationItem) -> Bool {
return lhs.id == rhs.id // ID가 같으면 같은 어노테이션으로 간주
}
}
28 changes: 28 additions & 0 deletions LocationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// LocationManager.swift
// MC2Maps
//
// Created by Evelyn Hong on 8/21/24.
//

import Foundation
import CoreLocation
import Combine

class LocationManager: NSObject, ObservableObject, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
@Published var location: CLLocation?

override init() {
super.init()
self.locationManager.delegate = self
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.locationManager.allowsBackgroundLocationUpdates = true // 백그라운드에서 동작
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
self.location = location
}
}
22 changes: 15 additions & 7 deletions MC2Maps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
/* Begin PBXBuildFile section */
A88329EE2C6DEBCC00D6CC87 /* MapLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */; };
A88329F22C71EA6100D6CC87 /* ModalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88329F12C71EA6100D6CC87 /* ModalView.swift */; };
A88CEC682C73164200B4B1EF /* Timetest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CEC672C73164200B4B1EF /* Timetest.swift */; };
A88CEC722C74F48200B4B1EF /* TimerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CEC712C74F48200B4B1EF /* TimerManager.swift */; };
A88CEC7A2C75CA5100B4B1EF /* AnnotationItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CEC792C75CA5100B4B1EF /* AnnotationItem.swift */; };
A88CEC7C2C75CB1200B4B1EF /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A88CEC7B2C75CB1200B4B1EF /* LocationManager.swift */; };
EAF2746D2C1C6B2C00D90AEA /* MC2MapsApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */; };
EAF2746F2C1C6B2C00D90AEA /* MapsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */; };
EAF274712C1C6B2E00D90AEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF274702C1C6B2E00D90AEA /* Assets.xcassets */; };
Expand All @@ -19,7 +21,9 @@
/* Begin PBXFileReference section */
A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLocation.swift; sourceTree = "<group>"; };
A88329F12C71EA6100D6CC87 /* ModalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalView.swift; sourceTree = "<group>"; };
A88CEC672C73164200B4B1EF /* Timetest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Timetest.swift; sourceTree = "<group>"; };
A88CEC712C74F48200B4B1EF /* TimerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerManager.swift; sourceTree = "<group>"; };
A88CEC792C75CA5100B4B1EF /* AnnotationItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnnotationItem.swift; sourceTree = "<group>"; };
A88CEC7B2C75CB1200B4B1EF /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = "<group>"; };
EAF274692C1C6B2C00D90AEA /* MC2Maps.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MC2Maps.app; sourceTree = BUILT_PRODUCTS_DIR; };
EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MC2MapsApp.swift; sourceTree = "<group>"; };
EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapsView.swift; sourceTree = "<group>"; };
Expand All @@ -42,6 +46,10 @@
EAF274602C1C6B2C00D90AEA = {
isa = PBXGroup;
children = (
A88CEC7B2C75CB1200B4B1EF /* LocationManager.swift */,
A88CEC792C75CA5100B4B1EF /* AnnotationItem.swift */,
A88CEC712C74F48200B4B1EF /* TimerManager.swift */,
A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */,
EAF2746B2C1C6B2C00D90AEA /* MC2Maps */,
EAF2746A2C1C6B2C00D90AEA /* Products */,
);
Expand All @@ -62,8 +70,6 @@
EAF2746C2C1C6B2C00D90AEA /* MC2MapsApp.swift */,
EAF2746E2C1C6B2C00D90AEA /* MapsView.swift */,
A88329F12C71EA6100D6CC87 /* ModalView.swift */,
A88329ED2C6DEBCC00D6CC87 /* MapLocation.swift */,
A88CEC672C73164200B4B1EF /* Timetest.swift */,
EAF274702C1C6B2E00D90AEA /* Assets.xcassets */,
EAF274722C1C6B2E00D90AEA /* Preview Content */,
);
Expand Down Expand Up @@ -150,9 +156,11 @@
files = (
EAF2746F2C1C6B2C00D90AEA /* MapsView.swift in Sources */,
EAF2746D2C1C6B2C00D90AEA /* MC2MapsApp.swift in Sources */,
A88CEC682C73164200B4B1EF /* Timetest.swift in Sources */,
A88CEC722C74F48200B4B1EF /* TimerManager.swift in Sources */,
A88CEC7C2C75CB1200B4B1EF /* LocationManager.swift in Sources */,
A88329F22C71EA6100D6CC87 /* ModalView.swift in Sources */,
A88329EE2C6DEBCC00D6CC87 /* MapLocation.swift in Sources */,
A88CEC7A2C75CA5100B4B1EF /* AnnotationItem.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -290,7 +298,7 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MC2Maps/Info.plist;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치정보를 사용합니다";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치정보를 사용합니다.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down Expand Up @@ -322,7 +330,7 @@
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MC2Maps/Info.plist;
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치정보를 사용합니다";
INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "사용자의 위치정보를 사용합니다.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand Down
Binary file not shown.
1 change: 1 addition & 0 deletions MC2Maps/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "Logo.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0d1313e

Please sign in to comment.