如何在watchOS 2中获取当前位置? [英] How to get the current location in watchOS 2?

查看:106
本文介绍了如何在watchOS 2中获取当前位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在watchOS 2中获取WatchKit App的用户当前位置.我该如何做?

I need to fetch the user current location for the WatchKit App in watchOS 2. How do I do this?

推荐答案

其他答案不正确.您可以直接在手表OS2的手表上请求位置.可用的方法称为requestLocation.它允许您请求一次位置更新.

The other answers are incorrect. You can request location directly on the watch for watch OS2. The available method is called requestLocation. It allows you to request a single location update.

例如

#import <CoreLocation/CoreLocation.h>
@interface className : WKInterfaceController<CLLocationManagerDelegate>

然后在您要请求位置的位置:

Then where you want to request location:

self.locationManager = [CLLocationManager new];
self.locationManager.delegate = self;
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestLocation];

然后,您将在以下CLLocationManagerDelegate方法之一中获得单个回调.

Then you will get a single callback in one of the following CLLocationManagerDelegate methods.

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    // Callback here with single location if location succeeds
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    // Error here if no location can be found
}

参见WWDC15视频核心位置的新增功能"- https://developer.apple.com/videos/wwdc/2015/?id=714

See the WWDC15 video "What's New in Core Location" - https://developer.apple.com/videos/wwdc/2015/?id=714

这篇关于如何在watchOS 2中获取当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆