开发者

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

Thi开发者_如何学Pythons question already has answers here: Closed 11 years ago.

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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜