在 Apple Watch 上检索位置 [英] Retrieving location on the Apple Watch
本文介绍了在 Apple Watch 上检索位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取用户的经纬度并显示在 Apple Watch 上.
I want to get the latitude and longitude of the user and display it on the Apple Watch.
我已经在我的 Watchkit 扩展中包含了核心定位框架.
I have already included the core location framework in my Watchkit Extension.
当我运行程序时,我得到的经纬度分别是 0.0 和 0.0
When I run the program all I get for the lat and long is 0.0 and 0.0
我在 iPhone 上的一个课程中测试了相同的方法,它奏效了,并给了我适当的坐标.我究竟做错了什么?
I tested the same method in a class on the iPhone and it worked, and gave me the appropriate coordinates. What am I doing wrong?
.h 文件:
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
@interface InterfaceController : WKInterfaceController
@end
.m 文件:
#import "InterfaceController.h"
@interface InterfaceController()
@end
@implementation InterfaceController
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
// Configure interface objects here.
}
- (void)willActivate {
// This method is called when watch view controller is about to be visible to user
[super willActivate];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
}
- (void)didDeactivate {
// This method is called when watch view controller is no longer visible
[super didDeactivate];
}
- (IBAction)showLocation {
NSString * geoLoc = [NSString stringWithFormat:@"latitude: %f longitude: %f", self.locationManager.location.coordinate.latitude, self.locationManager.location.coordinate.longitude];
NSLog(geoLoc);
}
@end
推荐答案
在 Xcode 中,您希望使用 调试 菜单来模拟预先设置的位置或使用 GPX 文件作为该位置来源.
In Xcode, you want use the Debug menu to simulate a location that's either pre-set or use a GPX file as the location source.
这篇关于在 Apple Watch 上检索位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文