根据经纬度计算两点之间的距离

/*
*根据经纬度计算距离
 */
    private static double EARTH_RADIUS = 6378.137;
    private static double RADIUS = 50;
    public  double getDistance(String projectLocation, double mapLocation[]){
        String projectLoc[] = projectLocation.split(",");
        double proLng = new Double(projectLoc[0]);
        double proLat = new Double(projectLoc[1]);
        double mapLng =mapLocation[0];
        double mapLat =mapLocation[1];
        proLat = rad(proLat);
        mapLat = rad(mapLat);
        double a = proLat - mapLat;
        double b = rad(proLng) - rad(mapLng);
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
                Math.cos(proLat) * Math.cos(mapLat) * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }

    /*
    *通过两个距离判断是否能够签到成功
    * 签到成功将信息保存到签到信息表中
     */

    @Override
    public Long checkIn(@Require Long id,@Require String address,@Require double mapLocation[],@Require int type) {
        CheckInEntity checkInEntity = new CheckInEntity();

        String houseLocation = houseService.get(projectService.get(id).getHouseId()).getMapCoordinates();
        String str=String.valueOf(mapLocation[0]) + String.valueOf(mapLocation[1]);
        double s =  getDistance(houseLocation,mapLocation);
        if(s <= RADIUS){
            checkInEntity.setAddress(address);
            checkInEntity.setBuilderId(UserContextHelper.getUserId());
            if(type==1){
                checkInEntity.setCheckTime(new Date());

            }else{
                checkInEntity.setCheckTime(new Date());
            }
            return create(checkInEntity);
        }
        else
            throw new ServiceException("未达到签到地点内,签到失败");
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值