【发布时间】:2015-02-03 00:48:25
【问题描述】:
我正在为 Swift 上的 Apple Watch 编写应用程序。我的目标是创建一种导航器,它可以显示您当前位置和地图上某个点之间的距离。目前我正在尝试获取当前位置并将其显示在屏幕上,但不幸的是代码不起作用。
这是 InterfaceController.swift 文件的代码。
class InterfaceController: WKInterfaceController, CLLocationManagerDelegate {
@IBOutlet weak var lblLocationDisplay: WKInterfaceLabel!;
let locationManager = CLLocationManager();
override func awakeWithContext(context: AnyObject?) {
super.awakeWithContext(context)
// Configure interface objects here.
}
override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}
override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
@IBAction func btnFindLocation() {
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.requestWhenInUseAuthorization();
locationManager.startUpdatingLocation();
}
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
CLGeocoder().reverseGeocodeLocation(manager.location, completionHandler: {(placemarks, error) -> Void in
println("Something");
let placeMarks = placemarks[0] as CLPlacemark;
self.displayLocation(placeMarks);
});
}
func displayLocation(placemark: CLPlacemark) {
// locationManager.stopUpdatingLocation();
println(placemark.country);
let locality = placemark.locality;
let postalCode = placemark.postalCode;
let administrativeArea = placemark.administrativeArea;
let country = placemark.country;
lblLocationDisplay.setText("Locality: \(locality) PostalCode: \(postalCode) Area: \(administrativeArea) Country: \(country)");
}
}
这里是project
请分享您对代码不起作用的原因的建议。我也希望你能建议我如何在手表中实现一个导航器应用程序。谢谢!
【问题讨论】:
标签: swift ios8 geolocation watchkit