// 문제에 대한 추가 정보가 있습니다. 위치 인증을 요청하지 않고 MapKit 위치 업데이트를 시작하려고합니다. 먼저 [CLLocationManager requestWhenInUseAuthorization] 또는 [CLLocationManager requestAlwaysAuthorization]을 호출해야합니다.현재 위치를지도에 표시하려하지만 시뮬레이터에서 코드를 실행할 때 작동하지 않습니다.
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet var myMap : MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
myMap.showsUserLocation = true }
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
print("locations = \(locValue.latitude) \(locValue.longitude)")
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError)
{
print("Errors: " + error.localizedDescription)
}
@IBAction func satelliteView(){
myMap.mapType = MKMapType.Satellite
}
@IBAction func normalView(){
myMap.mapType = MKMapType.Standard
}
@IBAction func pin(sender: UILongPressGestureRecognizer) {
let location = sender.locationInView(self.myMap)
let lCoord = self.myMap.convertPoint(location, toCoordinateFromView: self.myMap)
let anno = MKPointAnnotation()
anno.coordinate = lCoord
anno.title = "store"
anno.subtitle = "loctaion of Store"
self.myMap.removeAnnotations(myMap.annotations)
self.myMap.addAnnotation(anno)
}
}
당신은 '아무튼 무슨 뜻인지 설명해주십시오. t 작업 - 그렇지 않으면 당신을 도울 수있는 방법을 알기가 어렵습니다. – Feldur
시뮬레이터를 실행하면 세상의지도가 표시되고 현재 위치는 전혀 알려지지 않습니다 –
위치 대리인이 귀하에게 보내는 정보를 무시합니다. 인쇄하는 것보다 현재 위치가 표시되지 않는 이유입니다. 활성화되었을 때'pin' 기능은 무엇입니까? – Feldur