//第一种苹果自带的

  1. CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue]  longitude:[mainDelegate.longitude_self doubleValue]] autorelease];
  2. CLLocation* dist=[[[CLLocation alloc] initWithLatitude:[tmpNewsModel.latitude doubleValue] longitude:[tmpNewsModel.longitude doubleValue] ] autorelease];
  3. CLLocationDistance kilometers=[orig distanceFromLocation:dist]/1000;
  4. NSLog(@"距离:",kilometers);

//第二种,手动计算

  1. #pragma mark - calculate distance  根据2个经纬度计算距离
  2. #define PI 3.1415926
  3. +(double) LantitudeLongitudeDist:(double)lon1 other_Lat:(double)lat1 self_Lon:(double)lon2 self_Lat:(double)lat2{
  4. double er = 6378137; // 6378700.0f;
  5. //ave. radius = 6371.315 (someone said more accurate is 6366.707)
  6. //equatorial radius = 6378.388
  7. //nautical mile = 1.15078
  8. double radlat1 = PI*lat1/180.0f;
  9. double radlat2 = PI*lat2/180.0f;
  10. //now long.
  11. double radlong1 = PI*lon1/180.0f;
  12. double radlong2 = PI*lon2/180.0f;
  13. if( radlat1 < 0 ) radlat1 = PI/2 + fabs(radlat1);// south
  14. if( radlat1 > 0 ) radlat1 = PI/2 - fabs(radlat1);// north
  15. if( radlong1 < 0 ) radlong1 = PI*2 - fabs(radlong1);//west
  16. if( radlat2 < 0 ) radlat2 = PI/2 + fabs(radlat2);// south
  17. if( radlat2 > 0 ) radlat2 = PI/2 - fabs(radlat2);// north
  18. if( radlong2 < 0 ) radlong2 = PI*2 - fabs(radlong2);// west
  19. //spherical coordinates x=r*cos(ag)sin(at), y=r*sin(ag)*sin(at), z=r*cos(at)
  20. //zero ag is up so reverse lat
  21. double x1 = er * cos(radlong1) * sin(radlat1);
  22. double y1 = er * sin(radlong1) * sin(radlat1);
  23. double z1 = er * cos(radlat1);
  24. double x2 = er * cos(radlong2) * sin(radlat2);
  25. double y2 = er * sin(radlong2) * sin(radlat2);
  26. double z2 = er * cos(radlat2);
  27. double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
  28. //side, side, side, law of cosines and arccos
  29. double theta = acos((er*er+er*er-d*d)/(2*er*er));
  30. double dist  = theta*er;
  31. return dist;
  32. }

IOS根据两个经纬度计算相距距离的更多相关文章

  1. iOS-根据两个经纬度计算相距距离

    CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue] long ...

  2. js根据经纬度计算两点距离

    js版-胡老师 google.maps.LatLng.prototype.distanceFrom = function(latlng) {    var lat = [this.lat(), lat ...

  3. .NET资料之-根据两点经纬度计算直线距离

    最近做东西碰到要根据两点经纬度计算之间的直线距离,就网上找了查了下资料.因为这类接触的比较少,就直接找现成的代码了,没怎么研究.代码如下,作为记录. private const double EART ...

  4. 【微信开发】微信小程序通过经纬度计算两地距离php代码实现

    需求: 要求做个根据用户当前位置获取周围商家地址,并且按照由近到远排序, 方法一: 代码层实现 封装方法: /** * @desc 根据两点间的经纬度计算距离 * @param float $lat ...

  5. PHP 之根据两个经纬度计算距离

    一.函数代码 /** * @param $lng1 * @param $lat1 * @param $lng2 * @param $lat2 * @return float */ function g ...

  6. iOS 根据经纬度计算与地理北极夹角

    http://www.aiuxian.com/article/p-2767848.html #define toDeg(X) (X*180.0/M_PI) /**  * @method 根据两点经纬度 ...

  7. Geohash-》通过经纬度计算两地距离的函数

    /**      * 根据起点坐标和终点坐标测距离      * @param  [array]   $from  [起点坐标(经纬度),例如:array(118.012951,36.810024)] ...

  8. tp5 根据经纬度计算门店距离 可排序

    $branchInfo=Db::name('Branch')->where('b_id','250')->find(); $map['p.cate_id']=array('eq',5); ...

  9. mySQL函数根据经纬度计算两点距离

    DROP FUNCTION IF EXISTS func_calcDistance ; CREATE FUNCTION func_calcDistance( origLng ,), -- 目的地经度 ...

随机推荐

  1. 用好这6个APP,学英语SO EASY!

      http://www.jianshu.com/p/30a27af18340  

  2. 17 HTTP编程入门

    http请求原理 http请求原理我就不多说了,网上一搜就能搜索到,下面我注意是记录下http模块的使用方法 http 模块 HTTP-server hello world 我们使用HandleFun ...

  3. 7 云计算系列之Neutron安装与配置

    preface 紧接上一章,我们这里开始部署网络服务Neutron,可参考官网文档:http://docs.openstack.org/newton/install-guide-rdo/neutron ...

  4. ecshop学习1

    ECSHOP开发中心(www.68ecshop.com) 研究一下ecshop,先安装一下.下面是整个安装步骤: 1.下载ecshop程序包,下载地址: http://download.ecshop. ...

  5. if条件和for循环语句、while、do..while、switch语法

    //if 语句 ; ) { NSLog(@"不及格"); }) { NSLog(@"及格"); } //if语句 判断条件存在多个情况下,判断一个年是否为润年 ...

  6. 【代码审计】EasySNS_V1.6 前台任意文件下载漏洞分析

      0x00 环境准备 EasySNS官网:http://www.imzaker.com/ 网站源码版本:EasySNS极简社区V1.60 程序源码下载:http://es.imzaker.com/i ...

  7. 一句话shell

    作者:NetSeek1.删除0字节文件find -type f -size 0 -exec rm -rf {} \; 2.查看进程按内存从大到小排列ps -e -o "%C : %p : % ...

  8. Unity弹出MessageBox

    [DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = Char ...

  9. using 释放内存的写法

    using (FileStream fileStream = File.Open(fileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite) ...

  10. mybatis 之 parameterType="HashMap"参数包含list

    /** * 获得人气组合商品详情 * @param paramMap * @return */ public List<Goods> getCheckGoodsCombination(Ma ...