Leem.fin Leem.fin - 5 months ago 54
Objective-C Question

create CLLocation object in objective-c

I can initialize a

CLLocation
object by providing latitude and longitude like below:

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


How can I initialize a
CLLocation
object with not only latitude and longitude but also accuracy values?

Answer

As per apple docs you can use the following function:

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]]

In the example, for the parameters altitude and timestamp, I put the same defaults as what the apple docs say are used on -initWithLatitude:longitude: