오늘은 개발한 View의 버튼 이벤트를 구현했다.
그리고 View 간 이동이 잘 되는지 확인했고, 네이버 지도 SDK를 사용하는 법 더 공부했다!


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- 네이버 인증키 추가 -->
<key>NMFClientId</key>
<string>14njmv01hz</string>
<!-- 끝 -->
<!-- 유저 위치정보 가져오기 -->
<key>NSLocationAlwaysUsageDescription</key>
<string>사용자의 위치를 받습니다.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>위치정보 권한이 필요합니다.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>위치정보 권한이 필요합니다.</string>
<!-- 끝 -->
.
.
.
</dict>
</plist>
import UIKit
import NMapsMap
import CoreLocation
class ViewController: UIViewController {
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
print("위치 서비스 On 상태")
locationManager.startUpdatingLocation()
guard let location = locationManager.location else { return }
print(location.coordinate)
} else {
print("위치 서비스 Off 상태")
}
}
}
extension ViewController: NMFMapViewTouchDelegate {
func mapView(_ mapView: NMFMapView, didTapMap latlng: NMGLatLng, point: CGPoint) {
print("탭: \(latlng.lat), \(latlng.lng)")
}
}
extension ViewController: CLLocationManagerDelegate {
}


import UIKit
import NMapsMap
import CoreLocation
class ViewController: UIViewController {
var locationManager = CLLocationManager()
var lat: Double = 0.0
var lng: Double = 0.0
lazy var naverMapView = NMFNaverMapView(frame: view.frame)
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
naverMapView.showLocationButton = true
naverMapView.showCompass = true
view.addSubview(naverMapView)
naverMapView.mapView.touchDelegate = self
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
print("위치 서비스 On 상태")
locationManager.startUpdatingLocation()
guard let location = locationManager.location else { return }
print(location.coordinate)
} else {
print("위치 서비스 Off 상태")
}
}
}
extension ViewController: NMFMapViewTouchDelegate {
func mapView(_ mapView: NMFMapView, didTapMap latlng: NMGLatLng, point: CGPoint) {
print("탭: \(latlng.lat), \(latlng.lng)")
// 추기힌 코드
lat = latlng.lat
lng = latlng.lng
let marker = NMFMarker()
marker.position = NMGLatLng(lat: lat, lng: lng)
marker.mapView = naverMapView.mapView
}
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
print("현재 위치: \(location.coordinate.latitude), \(location.coordinate.longitude)")
let cameraUpdate = NMFCameraUpdate(scrollTo: NMGLatLng(lat: location.coordinate.latitude, lng: location.coordinate.longitude))
cameraUpdate.animation = .easeIn
naverMapView.mapView.moveCamera(cameraUpdate)
locationManager.stopUpdatingLocation()
}
}
