获取CLLocationCoordinate2D的正确方法是什么?
在.h中:
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;在.m中
//Called when the location can be obtained
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
//Get the latitude and longitude location
CLLocation *lastLocation = [locations lastObject];
_latitude = [[NSString alloc] initWithFormat:@"%f", lastLocation.coordinate.latitude];
_longitude = [[NSString alloc] initWithFormat:@"%f", lastLocation.coordinate.longitude];
}是这样的吗:
_coordinate = lastLocation.coordinate;或者这样:
_coordinate = manager.location.coordinate;发布于 2013-04-15 14:11:47
首先阅读已经在注释中说明的文档,因为这是位置编程的必备知识。
第二,注意这不是你从委托中得到的第一个数据,因为它可能是一个缓存的数据(你需要检查时间戳)或者是一个无效的数据(水平精度小于零)。
您可以使用该代码:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation * newLocation = [locations lastObject];
if (newLocation.horizontalAccuracy < 0) {
return;
}
NSTimeInterval interval = [newLocation.timestamp timeIntervalSinceNow];
if (abs(interval)>5) {
return;
}
//YOUR CODE HERE
}希望这对你有帮助,安德里亚
https://stackoverflow.com/questions/16006254
复制相似问题