ios 在 iPhone 的 gmap 中使用纬度-经度计算两个地方之间的距离
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7175412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Calculate distance between two place using latitude-longitude in gmap for iPhone
提问by Durga
Possible Duplicate:
GPS coordinates in degrees to calculate distances
可能的重复:
以度为单位的 GPS 坐标来计算距离
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 的 gmap 中使用纬度-经度计算两个地方之间的距离?在 iPhone 的 gmap 中使用纬度-经度计算两个地方之间的距离
回答by Vijay-Apple-Dev.blogspot.com
You have to use Core Location Framework. So don't forget to Add & import Core Location Framework.
您必须使用 Core Location Framework。所以不要忘记添加和导入核心定位框架。
Objective-C
目标-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)
回答by Nithin
if you have the location parameter, create 2 CLLocations and use [location1 distanceFromLocation:location2]
method.
如果您有位置参数,请创建 2 个 CLLocations 并使用[location1 distanceFromLocation:location2]
方法。