/* *根据经纬度计算距离 */ 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("未达到签到地点内,签到失败"); }
根据经纬度计算两点之间的距离
最新推荐文章于 2024-06-29 20:56:56 发布