0
그래서 내 ViewController.swift의 기능 안에서 내 위치를 얻으려고합니다.Swift를 사용하여 위치를 올바르게 가져올 수 없습니다.
var manager : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var locValue: CLLocationCoordinate2D = manager.location.coordinate
println("locations = \(locValue.longitude) \(locValue.latitude)")
manager.stopUpdatingLocation()
}
@IBAction func refresh() {
getWeatherData()
refreshButton.hidden = true
acitivityIndicatorView.hidden = false
acitivityIndicatorView.startAnimating()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func getWeatherData() -> Void {
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]!) {
var locValue: CLLocationCoordinate2D = manager.location.coordinate
println("locations = \(locValue.longitude) \(locValue.latitude)")
manager.stopUpdatingLocation()
동안 : 기능을 토글 버튼을 누른 상태에서
import UIKit
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
var manager : CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
manager.requestAlwaysAuthorization()
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
var locValue : CLLocationCoordinate2D
locValue = manager.location.coordinate
println("Coordinates = \(locValue.longitude) + \(locValue.latitude)")
manager.stopUpdatingLocation()
}
는하지만, 내가 뭘하려고 오전 그것을 얻을 것이다 :이처럼하려고 할 때
강령은 내가 작품을 사용 중단 점을 사용하면 locationManager를 func한다는 것을 깨달았지만 getweatherdata() 함수의 끝으로 이동합니다.
왜 작동하지 않는지 알 수 없습니다.
난 당신이 리프레시 기능 : –
넵에 manager.startUpdatingLocation()에 의해 getWeatherData()를 변경하는 것을 잊었다 생각합니다. 그게 내 바보 같았 어. 고마워요 :) – rakeshbs
와우, 고마워요! 나는 그것에 대해서 생각조차하지 못했지만, 그것이 의미있는 것은 맞습니다. 이제는 모두 작동합니다. 감사합니다! – Kvn92