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