我可以通过提供纬度和经度来初始化CLLocation对象,如下所示:

CLLocation *location =  [[CLLocation alloc] initWithLatitude:-43.242534 longitude:-54.93662];

如何初始化不仅具有纬度和经度而且还具有精度值的CLLocation对象?

最佳答案

对于苹果docs,您可以使用以下功能:

double desired_horizontal_accuracy = 200.0 // in meters
double desired_vertical_accuracy = 200.0 // in meters
[[CLLocation alloc] initWithCoordinate:CLLocationCoordinate2DMake(-43.242534,-54.93662)
                              altitude:-1
                    horizontalAccuracy:desired_horizontal_accuracy
                      verticalAccuracy:desired_vertical_accuracy
                             timestamp:[NSDate date]]

在示例中,对于参数altitudetimestamp,我设置了与 -initWithLatitude:longitude: 上使用的Apple文档相同的默认值

关于ios - 在Objective-C中创建CLLocation对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37886711/

10-11 11:39