IOS 通过 A 点坐标根据真北度数和增加公里数得到 B 点坐标

2017-10-10  本文已影响0人  Eleven_Lv

一搜全是计算两个坐标之间距离的算法, 数学不行, 自己对算法不是很精通, 折腾了好几天才写出来的, 如果有错误请留言谢谢

代码如下

/**

通过 A 点经纬度增加公里数得到 B 点经纬度

@param centerCoordinate  A 点坐标

@param distance 公里数(km)

@param radians  正北方向(0 ~ 360)

@return 返回值

*/

- (CLLocationCoordinate2D)calculateLatLng:(CLLocationCoordinate2D)centerCoordinate Distance:(CLLocationDistance)distance Radians:(CLLocationDistance)radians

{

static double Rc = 6378137;// 地球的赤道半径

static double Rj = 6356725;// 极半径

double m_LoDeg,m_LoMin,m_LoSec;

double m_LaDeg,m_LaMin,m_LaSec;

double m_Longitude,m_Latitude;

double m_RadLo,m_RadLa;

double Ec;

double Ed;

m_LaDeg = centerCoordinate.latitude;

m_LaMin = (centerCoordinate.latitude - m_LaDeg) * 60;

m_LaSec = (centerCoordinate.latitude - m_LaDeg-m_LaMin / 60) * 3600;

m_LoDeg = centerCoordinate.longitude;

m_LoMin = (centerCoordinate.longitude - m_LoDeg) * 60;

m_LoSec = (centerCoordinate.longitude - m_LoDeg - m_LoMin / 60) * 3600;

m_Longitude = centerCoordinate.longitude;

m_Latitude = centerCoordinate.latitude;

m_RadLo = centerCoordinate.longitude * M_PI / 180.;

m_RadLa = centerCoordinate.latitude * M_PI / 180.;

Ec = Rj + (Rc - Rj) * (90 - m_Latitude) / 90.;

Ed = Ec * cos(cos(M_PI / (180 / m_RadLa)));

double dx = distance * 1000 * sin(M_PI / (180 / radians));

double dy = distance * 1000 * cos(M_PI / (180 / radians));

CLLocationDegrees latitude = (dx / Ed + m_RadLo) * 180 / M_PI;

CLLocationDegrees longitude = (dy / Ec + m_RadLa) * 180 / M_PI;

CLLocationCoordinate2D newCoordinate;

newCoordinate.latitude = longitude;

newCoordinate.longitude = latitude;

return newCoordinate;

}

上一篇下一篇

猜你喜欢

热点阅读