首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何以米为单位测量两个CLLocations之间的距离?

如何以米为单位测量两个CLLocations之间的距离?
EN

Stack Overflow用户
提问于 2012-05-03 21:06:29
回答 4查看 26.6K关注 0票数 19

我怎样才能得到两个CLLocation之间以米为单位的距离呢?CLLocation没有提供任何这样做的方法,它看起来。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-05-03 21:09:01

代码语言:javascript
复制
CLLocationDistance distance = [aCLLocationA distanceFromLocation:aCLLocationB];
// distance is a double representing the distance in meters
票数 63
EN

Stack Overflow用户

发布于 2012-05-03 21:08:24

代码语言:javascript
复制
CLLocationDistance distance = [secondLocation distanceFromLocation:firstLocation];  //      distance is expressed in meters

CLLocationDistance kilometers = distance / 1000.0;
// or you can also use this..
CLLocationDistance meters = distance;

NSString *distanceString = [[NSString alloc] initWithFormat: @"%f", kilometers];

flot totaldistancecovered = [distanceString floatValue];

//Now,you can use this float value for addition...
// distanceMoved  should be float type variable which is declare in .h file...

 distanceMoved = distanceMoved + totaldistancecovered ;
 theLabel.text = [NSString stringWithFormat: @"%f meters", distanceMoved];

希望这能帮到你。

票数 5
EN

Stack Overflow用户

发布于 2012-05-03 21:09:36

代码语言:javascript
复制
CLLocation *loc1 = [[CLLocation alloc]  initWithLatitude:dblLatitude longitude:dblLongitude];   
CLLocation *loc2 = [[CLLocation alloc]  initWithLatitude:dblCurrentLatitude longitude:dblCurrentLongitude];
double dMeters = [loc1 distanceFromLocation:loc2];
[loc1 release];
[loc2 release];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10432023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档