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

IphoneIosGps

Iphone Problem Overview


> 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

Iphone Solutions


Solution 1 - Iphone

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDurgaView Question on Stackoverflow
Solution 1 - IphoneVijay-Apple-Dev.blogspot.comView Answer on Stackoverflow
Solution 2 - IphoneNithinView Answer on Stackoverflow