-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from School-of-Company/58-AddressChang-Coordin…
…ates 🔀 :: [#58] 주소를 좌표로 변경하는 기능
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// LocationManager.swift | ||
// Expo-iOS | ||
// | ||
// Created by 서지완 on 11/13/24. | ||
// Copyright © 2024 SchoolofCompany. All rights reserved. | ||
// | ||
|
||
import CoreLocation | ||
|
||
class LocationManager: ObservableObject { | ||
func getCoordinateFromAddress(address: String, completion: @escaping (CLLocationCoordinate2D?) -> Void) { | ||
let geocoder = CLGeocoder() | ||
geocoder.geocodeAddressString(address) { (placemarks, error) in | ||
guard let placemark = placemarks?.first, | ||
let location = placemark.location else { | ||
completion(nil) | ||
return | ||
} | ||
completion(location.coordinate) | ||
} | ||
} | ||
} | ||
|
||
/// *사용 예시 코드* | ||
//import SwiftUI | ||
//import CoreLocation | ||
// | ||
//struct ContentView: View { | ||
// @StateObject private var locationManager = LocationManager() | ||
// @State private var address = "" | ||
// @State private var coordinate: CLLocationCoordinate2D? | ||
// | ||
// var body: some View { | ||
// VStack { | ||
// TextField("주소를 입력하세요", text: $address) | ||
// .textFieldStyle(RoundedBorderTextFieldStyle()) | ||
// .padding() | ||
// | ||
// Button("좌표 변환") { | ||
// locationManager.getCoordinateFromAddress(address: address) { result in | ||
// self.coordinate = result | ||
// } | ||
// } | ||
// | ||
// if let coordinate = coordinate { | ||
// Text("위도: \(coordinate.latitude)") | ||
// Text("경도: \(coordinate.longitude)") | ||
// } | ||
// } | ||
// } | ||
//} |