我正在尝试找出 iphone 的当前位置,为此我正在使用这种方法。并尝试将其保存以供进一步处理。但是当我以纬度和经度的形式打印位置值时,它总是给我 0.00000 和 0.0000。我没有明白我错的地方。这个方法保存在 GetLocation 类中。
-(void)updatelocation{
NSLog(@"coming in update location in get location class");
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
NSLog(@"location manager %@", locationManager);
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude is: %f\n\n\n and longitude is: %f\n\n\n", location.coordinate.latitude, location.coordinate.longitude);
NSLog(@"coordinate %f",coordinate.latitude);
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:latitude forKey:@"latitude"];
[defaults setObject:longitude forKey:@"longitude"];
}
当我在这样的另一个类中调用此方法时。
GetLocation *location = [GetLocation alloc] init ];
[location updatelocation];
但我总是得到 0.0000 和 0.0000。谁能告诉我我错在哪里。