zoukankan      html  css  js  c++  java
  • 计算纬度、经度距离,返回公里(千米)数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ClDing.Utility
    {
    /// <summary>
    /// 计算纬度、经度距离
    /// </summary>
    public class Distance
    {
    private const double EARTH_RADIUS = 6378.137;//地球半径

    private static double Rad(double d)
    {
    return d * Math.PI / 180.0;
    }

    /// <summary>
    /// 计算纬度、经度距离,返回公里(千米)数
    /// </summary>
    /// <param name="lat1">纬度1</param>
    /// <param name="lng1">经度1</param>
    /// <param name="lat2">纬度2</param>
    /// <param name="lng2">经度2</param>
    /// <returns></returns>
    public static double Comput(double lat1, double lng1, double lat2, double lng2)
    {
    double radLat1 = Rad(lat1);
    double radLat2 = Rad(lat2);
    double a = Math.Abs(radLat1 - radLat2);
    double b = Math.Abs(Rad(lng1) - Rad(lng2));

    double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +
    Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
    s = s * EARTH_RADIUS;
    s = Math.Round(s * 10000, 0) / 10000;
    return s;
    }
    }
    }

  • 相关阅读:
    【LOJ#6277】数列分块1
    【LOJ6284】数列分块8
    【洛谷P3275】糖果
    【洛谷P3810】陌上花开
    【洛谷P1052】过河 离散化+dp
    【洛谷P2042】维护数列
    【模板】文艺平衡树
    【洛谷P4145】花神游历各国
    【洛谷P4878】布局
    hdu 5748(LIS)
  • 原文地址:https://www.cnblogs.com/zhangxiaolei521/p/5543622.html
Copyright © 2011-2022 走看看