gpt4 book ai didi

ios - 如何从locationManager获取viewDidLoad的坐标?

转载 作者:行者123 更新时间:2023-11-29 04:43:11 25 4
gpt4 key购买 nike

我的问题是:如何将 locationManager 坐标获取到我的 viewDidLoad 方法,以使用我之前检查的位置加载我的地​​图 View ???

我的 locationManager 看起来像这样(UIlabel 的字符串):

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
if (wasFound) return;
wasFound = YES;

CLLocationCoordinate2D loc = [newLocation coordinate];


latitude.text = [NSString stringWithFormat: @"%f", loc.latitude];
longitude.text = [NSString stringWithFormat: @"%f", loc.longitude];

我的 viewDidLoad 像这样:

 CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 37.786996;
theCoordinate1.longitude = -122.419281;

所以我想将我的真实坐标插入到纬度和经度位置!

谢谢!

最佳答案

CLLocationCooperative2D loc 设为 didUpdateToLocation: 方法所在的任何对象的属性。如果它与 viewDidLoad 代码是同一对象,则直接使用即可。如果它在其他类中,请在 View Controller 中引用该类并以这种方式获取属性。

关于ios - 如何从locationManager获取viewDidLoad的坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10055313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com