//第一种苹果自带的

  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. vue学习起步,vue环境安装

    vue安装的前提是安装了nodejs 安装淘宝镜像 npm install -g cnpm --registry=https://registry.npm.taobao.org 安装webpack c ...

  2. WebGL 颜色与纹理

    1.纹理坐标 纹理坐标是纹理图像上的坐标,通过纹理坐标可以在纹理图像上获取纹理颜色.WebGL系统中的纹理坐标系统是二维的,如图所示.为了将纹理坐标和广泛使用的x.y坐标区分开来,WebGL使用s和t ...

  3. Chrome扩展应用

    现在越来越多的用户将chrome浏览器设置为自己默认的浏览器,不仅是因为他的界面美,最重要的是他对html5和CSS3完美的支持,且调试工具非常好用,还有丰富的扩展库.如何安装自己的扩展呢? 点击自定 ...

  4. 5 -- Hibernate的基本用法 --3 Hibernate的体系结构

    ⊙ SessionFactory : 这是Hibernate的关键对象,它是单个数据库映射关系经过编译后的内存镜像,也是线程安全的.它是生成Session的工厂,本身需要依赖于ConnectionPr ...

  5. ios开发之--理解NSStringDrawingOptions每个选项的用法与意义

    typedef NS_OPTIONS(NSInteger, NSStringDrawingOptions) { NSStringDrawingUsesLineFragmentOrigin = < ...

  6. 【GIS】postgres(postgis) --》nodejs+express --》geojson --》leaflet

    一.基本架构 1.数据存储层:PostgreSQL-9.2.13 + postgis_2_0_pg92 2.业务处理层:Nodejs + Express + PG驱动 3.前端展示层:Leaflet ...

  7. Jsoup(三)-- Jsoup使用选择器语法查找DOM元素

    1.Jsoup可以使用类似于CSS或jQuery的语法来查找和操作元素. 2.实例如下: public static void main(String[] args) throws Exception ...

  8. NSIS安装vcredist_64.exe

    ; ExecWait ‘vcredist_x86.exe’ # 一般的安装ExecWait ‘”vcredist_x86.exe” /q’ # silent install 静默安装; ExecWai ...

  9. ISD9160学习笔记04_ISD9160音频编码代码分析

    前言 录音例程涉及了录音和播放两大块内容,上篇笔记说了播放,这篇就来说说录音这块,也就是音频编码这部分功能. 上篇笔记中的这段话太装逼了,我决定再复制下,嘿嘿. “我的锤子便签中有上个月记下的一句话, ...

  10. Android学习之PopupWindow

    Android的对话框有两种:PopupWindow和AlertDialog. 详细说明如下: AlertDialog是非阻塞式对话框:AlertDialog弹出时,后台还可以做事情: AlertDi ...