Distance between 2 points with CLLocationCoordinate2D

Viewed 12010

Details

I'm trying to measure the distance between two coordinates on a map (longitude, latitude). The first coordinate is my current location which is a CLLocation, and the other one is a pin on the map which is of type CLLocationCoordinate2D.

Issue

I call distanceFromLocation to get my current location in CLLocation but it says bad receiver type from CLLocationCoordinate2D.

CLLocationCoordinate2D locationCoordinate;

// Set the latitude and longitude
locationCoordinate.latitude  = [[item objectForKey:@"lat"] doubleValue];
locationCoordinate.longitude = [[item objectForKey:@"lng"] doubleValue];

CLLocationDistance dist = [locationCoordinate distanceFromLocation:locationManager.location.coordinate]; // bad receiver type from CLLocationCoordinate2D

Question

I want to find the distance between these 2 coordinates in metric unit, and I know that types are mismatching, but how to convert them so I can find the distance between these 2 nodes?

4 Answers
Related