gpt4 book ai didi

ios - 使用iOS版Google Maps API无法获取当前位置坐标

转载 作者:行者123 更新时间:2023-12-01 18:14:19 25 4
gpt4 key购买 nike

我尝试了以下代码:

- (void)viewDidLoad
{
[super viewDidLoad];
mapView_.myLocationEnabled = YES;

CLLocation *myLocation = mapView_.myLocation;
NSLog(@"%f %f",myLocation.coordinate.latitude, myLocation.coordinate.longitude);
}

正在记录的输出为0.000000 0.000000。

我还检查了设置,启用了位置服务,并且还显示了我的应用已启用。

请帮助我找出我要去哪里。

最佳答案

viewDidLoad中始终显示为0,0,您将不得不使用KVO来观察坐标。尝试以下代码:-

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.mapView addObserver:self forKeyPath:@"myLocation" options:NSKeyValueObservingOptionNew context: nil];
}

-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.mapView removeObserver:self forKeyPath:@"myLocation"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"myLocation"] && [object isKindOfClass:[GMSMapView class]])
{
NSLog(@"KVO triggered. Location Latitude: %f Longitude: %f",self.mapView.myLocation.coordinate.latitude,self.mapView.myLocation.coordinate.longitude);
}
}

关于ios - 使用iOS版Google Maps API无法获取当前位置坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24112469/

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