java测量两点的距离

package com.opensesame.core.util;


public class DistanceUtil {

    //测量两点的距离(fromPoint:经度纬度;toPoint:经度纬度)
    public static long measureDistance(LatLon fromPoint, LatLon toPoint) {

        double EARTH_RADIUS = 6378137;

        long distance = 0l;

        double startLongitude = Double.valueOf(fromPoint.getLongitude());

        double startLatitude = Double.valueOf(fromPoint.getLatitude());

        double endLongitude = Double.valueOf(toPoint.getLongitude());

        double endLatitude = Double.valueOf(toPoint.getLatitude());

        double radLatitude1 = startLatitude * Math.PI / 180.0;

        double radLatitude2 = endLatitude * Math.PI / 180.0;

        double a = Math.abs(radLatitude1 - radLatitude2);

        double b = Math.abs(startLongitude * Math.PI / 180.0 - endLongitude * Math.PI / 180.0);

        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)

                + Math.cos(radLatitude1) * Math.cos(radLatitude2) * Math.pow(Math.sin(b / 2), 2)));

        s = s * EARTH_RADIUS;

        distance = Math.round(s * 10000) / 10000; // 返回距离单位是米

        return distance;

    }


//    public static void main(String[]arg0){
//        // 北京市朝阳区阜通东大街6号转换后经纬度:116.480881,39.989410
//        // 天安门转换后经纬度:116.397499,39.908722
//        LatLon f = new LatLon();
//        LatLon t = new LatLon();
//
//        f.setLongitude(Double.valueOf("123.437834"));
//        f.setLatitude(Double.valueOf("41.756178"));
//
//        t.setLongitude(Double.valueOf("123.435914"));
//        t.setLatitude(Double.valueOf("41.760092"));
//
//        System.out.println(measureDistance(t,f));
//
        System.out.println(InspectionHouseUtil.firstInspectionTime(200.00,1,0)/60);
//    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值