Skip to content

Commit

Permalink
Merge pull request #14 from exinferis/exinferis
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrushy authored Oct 9, 2024
2 parents bd5d430 + 88d046f commit 4beb992
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code Relay/Code Relay/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
}
}
}
},
"Selected Coordinate" : {

},
"Settings" : {
"localizations" : {
Expand Down
52 changes: 52 additions & 0 deletions Code Relay/Code Relay/NewLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import SwiftUI
import CoreLocation
import MapKit

public struct NewLocationView: View {
@Environment(\.dismiss) var dismiss
Expand All @@ -18,7 +19,19 @@ public struct NewLocationView: View {
@State var long: Double?
@State var phoneNumber: String

// Init the location with the current coordinates if applicable
@State var location: Location

public var body: some View {

var region: Binding<MKCoordinateRegion> = Binding {
MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: lat ?? 0, longitude: long ?? 0),
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
)
} set: {_ in }


NavigationStack {
VStack {
List {
Expand All @@ -41,6 +54,19 @@ public struct NewLocationView: View {
.onSubmit {
field = field?.next
}

Spacer()
Map {
Marker("Selected Coordinate", coordinate: CLLocationCoordinate2D(latitude: lat ?? 0, longitude: long ?? 0))
}
.cornerRadius(10)
.padding(.horizontal, 24)
.padding(.top, 24)
.padding(.bottom, 12)
.frame(height: 250)
.frame(maxWidth: .infinity)
Spacer()

Button {
let coordinate: CLLocationCoordinate2D? = if let lat, let long {
.init(latitude: lat, longitude: long)
Expand Down Expand Up @@ -72,7 +98,33 @@ public struct NewLocationView: View {
.padding(.horizontal, 24)
}
.navigationTitle("Add New Location")
}.onChange(of: lat ?? 0) { oldValue, newValue in
region.wrappedValue = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: lat ?? 0, longitude: long ?? 0),
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
)
}
.onChange(of: long ?? 0) { oldValue, newValue in
region.wrappedValue = MKCoordinateRegion(
center: CLLocationCoordinate2D(latitude: lat ?? 0, longitude: long ?? 0),
span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
)
}
}

init(
title: String,
details: String,
lat: Double? = nil,
long: Double? = nil,
phoneNumber: String
) {
self.title = title
self.details = details
self.lat = lat
self.long = long
self.phoneNumber = phoneNumber
self.location = Location(title: "", details: "", coordinate: CLLocationCoordinate2D(latitude: lat ?? 0, longitude: long ?? 0), phoneNumber: "")
}
}

Expand Down

0 comments on commit 4beb992

Please sign in to comment.