IOS根据两个经纬度计算相距距离
//第一种苹果自带的
- CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue] longitude:[mainDelegate.longitude_self doubleValue]] autorelease];
- CLLocation* dist=[[[CLLocation alloc] initWithLatitude:[tmpNewsModel.latitude doubleValue] longitude:[tmpNewsModel.longitude doubleValue] ] autorelease];
- CLLocationDistance kilometers=[orig distanceFromLocation:dist]/1000;
- NSLog(@"距离:",kilometers);
//第二种,手动计算
- #pragma mark - calculate distance 根据2个经纬度计算距离
- #define PI 3.1415926
- +(double) LantitudeLongitudeDist:(double)lon1 other_Lat:(double)lat1 self_Lon:(double)lon2 self_Lat:(double)lat2{
- double er = 6378137; // 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 < 0 ) radlat1 = PI/2 + fabs(radlat1);// south
- if( radlat1 > 0 ) radlat1 = PI/2 - fabs(radlat1);// north
- if( radlong1 < 0 ) radlong1 = PI*2 - fabs(radlong1);//west
- if( radlat2 < 0 ) radlat2 = PI/2 + fabs(radlat2);// south
- if( radlat2 > 0 ) radlat2 = PI/2 - fabs(radlat2);// north
- if( radlong2 < 0 ) radlong2 = PI*2 - 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)/(2*er*er));
- double dist = theta*er;
- return dist;
- }
IOS根据两个经纬度计算相距距离的更多相关文章
- iOS-根据两个经纬度计算相距距离
CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue] long ...
- js根据经纬度计算两点距离
js版-胡老师 google.maps.LatLng.prototype.distanceFrom = function(latlng) { var lat = [this.lat(), lat ...
- .NET资料之-根据两点经纬度计算直线距离
最近做东西碰到要根据两点经纬度计算之间的直线距离,就网上找了查了下资料.因为这类接触的比较少,就直接找现成的代码了,没怎么研究.代码如下,作为记录. private const double EART ...
- 【微信开发】微信小程序通过经纬度计算两地距离php代码实现
需求: 要求做个根据用户当前位置获取周围商家地址,并且按照由近到远排序, 方法一: 代码层实现 封装方法: /** * @desc 根据两点间的经纬度计算距离 * @param float $lat ...
- PHP 之根据两个经纬度计算距离
一.函数代码 /** * @param $lng1 * @param $lat1 * @param $lng2 * @param $lat2 * @return float */ function g ...
- iOS 根据经纬度计算与地理北极夹角
http://www.aiuxian.com/article/p-2767848.html #define toDeg(X) (X*180.0/M_PI) /** * @method 根据两点经纬度 ...
- Geohash-》通过经纬度计算两地距离的函数
/** * 根据起点坐标和终点坐标测距离 * @param [array] $from [起点坐标(经纬度),例如:array(118.012951,36.810024)] ...
- tp5 根据经纬度计算门店距离 可排序
$branchInfo=Db::name('Branch')->where('b_id','250')->find(); $map['p.cate_id']=array('eq',5); ...
- mySQL函数根据经纬度计算两点距离
DROP FUNCTION IF EXISTS func_calcDistance ; CREATE FUNCTION func_calcDistance( origLng ,), -- 目的地经度 ...
随机推荐
- 用好这6个APP,学英语SO EASY!
http://www.jianshu.com/p/30a27af18340
- 17 HTTP编程入门
http请求原理 http请求原理我就不多说了,网上一搜就能搜索到,下面我注意是记录下http模块的使用方法 http 模块 HTTP-server hello world 我们使用HandleFun ...
- 7 云计算系列之Neutron安装与配置
preface 紧接上一章,我们这里开始部署网络服务Neutron,可参考官网文档:http://docs.openstack.org/newton/install-guide-rdo/neutron ...
- ecshop学习1
ECSHOP开发中心(www.68ecshop.com) 研究一下ecshop,先安装一下.下面是整个安装步骤: 1.下载ecshop程序包,下载地址: http://download.ecshop. ...
- if条件和for循环语句、while、do..while、switch语法
//if 语句 ; ) { NSLog(@"不及格"); }) { NSLog(@"及格"); } //if语句 判断条件存在多个情况下,判断一个年是否为润年 ...
- 【代码审计】EasySNS_V1.6 前台任意文件下载漏洞分析
0x00 环境准备 EasySNS官网:http://www.imzaker.com/ 网站源码版本:EasySNS极简社区V1.60 程序源码下载:http://es.imzaker.com/i ...
- 一句话shell
作者:NetSeek1.删除0字节文件find -type f -size 0 -exec rm -rf {} \; 2.查看进程按内存从大到小排列ps -e -o "%C : %p : % ...
- Unity弹出MessageBox
[DllImport("User32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = Char ...
- using 释放内存的写法
using (FileStream fileStream = File.Open(fileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite) ...
- mybatis 之 parameterType="HashMap"参数包含list
/** * 获得人气组合商品详情 * @param paramMap * @return */ public List<Goods> getCheckGoodsCombination(Ma ...