栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java测量两点的距离

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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);
//    }


}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/979029.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号