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

Durga picture Durga · Aug 24, 2011 · Viewed 70.1k times · Source

Possible Duplicate:
GPS coordinates in degrees to calculate distances

How to Calculate distance between two place using latitude-longitude in gmap for iPhone? Calculate distance between two place using latitude-longitude in gmap for iPhone

Answer

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)