zoukankan      html  css  js  c++  java
  • iOS 地图 通过经纬度计算两点间距离

    - (double)calculateStart:(CLLocationCoordinate2D)start end:(CLLocationCoordinate2D)end {
        
        double meter = 0;
        
        double startLongitude = start.longitude;
        double startLatitude = start.latitude;
        double endLongitude = end.longitude;
        double endLatitude = end.latitude;
        
        double radLatitude1 = startLatitude * M_PI / 180.0;
        double radLatitude2 = endLatitude * M_PI / 180.0;
        double a = fabs(radLatitude1 - radLatitude2);
        double b = fabs(startLongitude * M_PI / 180.0 - endLongitude * M_PI / 180.0);
        
        double s = 2 * asin(sqrt(pow(sin(a/2),2) + cos(radLatitude1) * cos(radLatitude2) * pow(sin(b/2),2)));
        s = s * EARTH_RADIUS;
        
        meter = round(s * 10000) / 10000; //返回距离单位是米
        return meter;
    }
    //赤道半径
    EARTH_RADIUS = 6378137;
    //start 起点经纬度,数据格式 start = {lon:,lat:}
    //end 终点定位度,数据格式 end = {lon:,lat:}
  • 相关阅读:
    vsync信号产生与分发
    推荐看过不错的博客及网站
    证明质数有无数个
    242 Valid Anagram
    169 Majority Element
    快速排序--quicksort
    插入排序
    选择排序
    冒泡排序
    指针函数 函数指针 回调函数
  • 原文地址:https://www.cnblogs.com/liuliuliu/p/4551379.html
Copyright © 2011-2022 走看看