#pragma mark - calculate distance  根据2个经纬度计算距离

 #define PI 3.14159265358979323
+(double) CalculationDistanceOther_Lon1:(double)lon1 Other_Lat1:(double)lat1 self_Lon2:(double)lon2 self_Lat2:(double)lat2{
double er = ; // 6378700.0f;
//ave. radius = 6371.315 (someone said more accurate is 6366.707)
//equatorial radius = 6378.388
//nautical mile = 1.15078
double radlat1 = PI*lat1/180.0f;
double radlat2 = PI*lat2/180.0f;
//now long.
double radlong1 = PI*lon1/180.0f;
double radlong2 = PI*lon2/180.0f;
if( radlat1 < ) radlat1 = PI/ + fabs(radlat1);// south
if( radlat1 > ) radlat1 = PI/ - fabs(radlat1);// north
if( radlong1 < ) radlong1 = PI* - fabs(radlong1);//west
if( radlat2 < ) radlat2 = PI/ + fabs(radlat2);// south
if( radlat2 > ) radlat2 = PI/ - fabs(radlat2);// north
if( radlong2 < ) radlong2 = PI* - fabs(radlong2);// west
//spherical coordinates x=r*cos(ag)sin(at), y=r*sin(ag)*sin(at), z=r*cos(at)
//zero ag is up so reverse lat
double x1 = er * cos(radlong1) * sin(radlat1);
double y1 = er * sin(radlong1) * sin(radlat1);
double z1 = er * cos(radlat1);
double x2 = er * cos(radlong2) * sin(radlat2);
double y2 = er * sin(radlong2) * sin(radlat2);
double z2 = er * cos(radlat2);
double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
//side, side, side, law of cosines and arccos
double theta = acos((er*er+er*er-d*d)/(*er*er));
double dist = theta*er;
return dist;
}

最新文章

  1. 跨平台的 .NET 运行环境 Mono 3.2 新特性
  2. 3-Spark高级数据分析-第三章 音乐推荐和Audioscrobbler数据集
  3. java 自带md5加密
  4. 二、Spring——AoP
  5. java web开发 图片上传功能
  6. C#:使用MD5对用户密码加密与解密
  7. emacs下安装pip
  8. arcgis js api 本地化配置
  9. 硬菜点播台 | MySQL阿里实践经典案例之参数调优最佳实践
  10. winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏
  11. Python开发【第二十一篇】:Web框架之Django【基础】
  12. javascript权威指南学习笔记2
  13. js编程风格
  14. PhantomJS是一个基于WebKit的服务器端JavaScript API
  15. MYSQL数据库45道练习题
  16. js_11_dom其他
  17. python实现汉诺塔移动
  18. hadoop端口使用配置总结(非常好的总结)
  19. Codeforces.1043F.Make It One(DP 容斥)
  20. 使用Epplus生成Excel 图表

热门文章

  1. C#整理2——C#的输入输出及基本类型
  2. UVA 10305 Ordering Tasks
  3. 仅当使用了列的列表并且 IDENTITY_INSERT 为 ON 时,才能为表&#39;SpeType&#39;中的标识列指定显式值
  4. zoj1107 FatMouse and Cheese
  5. mysql 批量更新
  6. 将Eclipse代码导入到Android Studio的两种方式
  7. JS中如何使用Cookie
  8. 设置windows窗口半透明(使用SetLayeredWindowAttributes API函数)
  9. 关于“找不到附属汇编 Microsoft.VC90.CRT,上一个错误是 参照的汇编没有安装在系统上。”的解决
  10. Qt widgets