Calculate distance between two place using latitude-longitude in gmap for iPhone [duplicate]

Solution 1:

You have to use Core Location Framework. So don't forget to Add & import Core Location Framework.

Objective-C

 #import <CoreLocation/CoreLocation.h>

 CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

 CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

 CLLocationDistance distance = [locA distanceFromLocation:locB];

 //distance in Meters

 //1 meter == 100 centimeter

 //1 meter == 3.280 feet

 //1 square meter == 10.76 square feet


 [locA release];

 [locB release];

Swift

import CoreLocation

let locA = CLLocation(latitude: lat1, longitude: long1)

let locB = CLLocation(latitude: lat2, longitude: long2)

let distance = locA.distance(from: locB)

Solution 2:

if you have the location parameter, create 2 CLLocations and use [location1 distanceFromLocation:location2] method.