1
我有一个按钮,当您按下按钮时,您将获得该位置。它只适用于初次启动,而不是后续使用。下面的代码IBAction仅在首次发布时获取核心位置位置
- (IBAction)getLocationCoordinates:(UIButton *)sender {
if ([CLLocationManager locationServicesEnabled]) {
self.locationManager = [[CLLocationManager alloc]init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation *location = [locations lastObject];
[self.locationManager stopUpdatingLocation];
NSLog(@"%f %f", location.coordinate.longitude, location.coordinate.latitude);
self.locationProperty = location;
}
很酷。我会看看。当我改变模拟位置时,我没有得到新的位置,我得到了旧位置。说我选择墨西哥城,然后我换到纽约,我又得到墨西哥城的数据。我可能也没有正确实现CLLocationManager。 – noobsmcgoobs
我相信你测试位置的方式不正确。你的物理设备必须移动一小段距离,因为iOS使用加速计来知道设备是否实际移动。或者你知道如何刺激加速度计的运动,如http://www.scottlogic.com/blog/2014/03/19/simulator-enhancements.html – Ricky
@Ricky:请避免用“Please upvote .. “。它只是增加了噪音。 – Matt