|
|
@@ -1,10 +1,7 @@
|
|
|
package bus.service.impl;
|
|
|
|
|
|
import bus.model.SnowflakeUtil;
|
|
|
-import bus.model.dto.BCourseBusDto;
|
|
|
-import bus.model.dto.BCourseInfoDto;
|
|
|
-import bus.model.dto.BCourseStationDto;
|
|
|
-import bus.model.dto.BCourseTimeDto;
|
|
|
+import bus.model.dto.*;
|
|
|
import bus.model.dto.page.BCourseInfoPageDto;
|
|
|
import bus.model.po.*;
|
|
|
import bus.model.vo.BCourseInfoVo;
|
|
|
@@ -12,6 +9,9 @@ import bus.mapper.BCourseInfoMapper;
|
|
|
|
|
|
import bus.service.*;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.orcas.common.sso.model.ExtInfo;
|
|
|
@@ -22,8 +22,8 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -50,6 +50,7 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
private BCourseBusService bCourseBusService;
|
|
|
@Resource
|
|
|
private BBusInfoService bBusInfoService;
|
|
|
+
|
|
|
/**
|
|
|
* 详情
|
|
|
* @param id
|
|
|
@@ -59,7 +60,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
public BCourseInfoDto getDetailById(String id){
|
|
|
BCourseInfoPo po = this.bCourseInfoMapper.selectById(id);
|
|
|
BCourseInfoDto bCourseInfoDto = BeanUtil.toBean(po, BCourseInfoDto.class);
|
|
|
-
|
|
|
+ String mapPoint = po.getMapPoint();
|
|
|
+ if(StrUtil.isNotBlank(mapPoint)) {
|
|
|
+ List<BCoursePointDto> fileJsons = JSONUtil.toList(mapPoint, BCoursePointDto.class);
|
|
|
+ bCourseInfoDto.setMapPointList(fileJsons);
|
|
|
+ }
|
|
|
QueryWrapper<BCourseTimePo> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("course_id", id);
|
|
|
queryWrapper.orderByAsc("sort");
|
|
|
@@ -71,21 +76,65 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
queryWrapper1.eq("course_id", id);
|
|
|
queryWrapper1.orderByAsc("sort");
|
|
|
List<BCourseStationPo> list1 = bCourseStationService.list(queryWrapper1);
|
|
|
- List<String> stationIds = list1.stream().map(BCourseStationPo::getStationId).collect(Collectors.toList());
|
|
|
- QueryWrapper<BStationInfoPo> queryWrapper2 = new QueryWrapper<>();
|
|
|
- queryWrapper2.in("id", stationIds);
|
|
|
- List<BStationInfoPo> list2 = bStationInfoService.list(queryWrapper2);
|
|
|
- bCourseInfoDto.setBCourseStationList(BeanUtil.copyToList(list2, BCourseStationDto.class));
|
|
|
+ if(CollectionUtil.isNotEmpty(list1)) {
|
|
|
+ List<String> stationIds = list1.stream().map(BCourseStationPo::getStationId).collect(Collectors.toList());
|
|
|
+ QueryWrapper<BStationInfoPo> queryWrapper2 = new QueryWrapper<>();
|
|
|
+ queryWrapper2.in("id", stationIds);
|
|
|
+ List<BStationInfoPo> list2 = bStationInfoService.list(queryWrapper2);
|
|
|
+ Map<String,BStationInfoPo> collect = list2.stream().collect(Collectors.toMap(BStationInfoPo::getId, b -> b));
|
|
|
+ List<BCourseStationDto> list5 = new ArrayList<>();
|
|
|
+ for (BCourseStationPo bCourseStationPo : list1 ) {
|
|
|
+ String stationId = bCourseStationPo.getStationId();
|
|
|
+ BStationInfoPo bStationInfoPo = collect.get(stationId);
|
|
|
+ if(bStationInfoPo != null) {
|
|
|
+ BCourseStationDto bCourseStationDto = new BCourseStationDto();
|
|
|
+ bCourseStationDto.setId(bCourseStationPo.getId());
|
|
|
+ bCourseStationDto.setStationId(bCourseStationPo.getStationId());
|
|
|
+ bCourseStationDto.setSort(bCourseStationPo.getSort());
|
|
|
+ bCourseStationDto.setType(bCourseStationPo.getType());
|
|
|
+ bCourseStationDto.setRemark(bCourseStationPo.getRemark());
|
|
|
+ bCourseStationDto.setName(bStationInfoPo.getName());
|
|
|
+ bCourseStationDto.setStationType(bStationInfoPo.getStationType());
|
|
|
+ bCourseStationDto.setStationStatus(bStationInfoPo.getStationStatus());
|
|
|
+ bCourseStationDto.setDetailAddress(bStationInfoPo.getDetailAddress());
|
|
|
+ bCourseStationDto.setStationCode(bStationInfoPo.getStationCode());
|
|
|
+ bCourseStationDto.setLatitude(bStationInfoPo.getLatitude());
|
|
|
+ bCourseStationDto.setLongitude(bStationInfoPo.getLongitude());
|
|
|
+ list5.add(bCourseStationDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bCourseInfoDto.setBCourseStationList(list5);
|
|
|
+ }
|
|
|
|
|
|
QueryWrapper<BCourseBusPo> queryWrapper3 = new QueryWrapper<>();
|
|
|
queryWrapper3.eq("course_id", id);
|
|
|
queryWrapper3.orderByAsc("sort");
|
|
|
List<BCourseBusPo> list3 = bCourseBusService.list(queryWrapper3);
|
|
|
- List<String> busIds = list3.stream().map(BCourseBusPo::getBusId).collect(Collectors.toList());
|
|
|
- QueryWrapper<BBusInfoPo> queryWrapper4 = new QueryWrapper<>();
|
|
|
- queryWrapper4.in("id", busIds);
|
|
|
- List<BBusInfoPo> list4 = bBusInfoService.list(queryWrapper4);
|
|
|
- bCourseInfoDto.setBCourseBusList(BeanUtil.copyToList(list4, BCourseBusDto.class));
|
|
|
+ if(CollectionUtil.isNotEmpty(list3)) {
|
|
|
+ List<String> busIds = list3.stream().map(BCourseBusPo::getBusId).collect(Collectors.toList());
|
|
|
+ QueryWrapper<BBusInfoPo> queryWrapper4 = new QueryWrapper<>();
|
|
|
+ queryWrapper4.in("id", busIds);
|
|
|
+ List<BBusInfoPo> list4 = bBusInfoService.list(queryWrapper4);
|
|
|
+ Map<String,BBusInfoPo> collect = list4.stream().collect(Collectors.toMap(BBusInfoPo::getId, b -> b));
|
|
|
+ List<BCourseBusDto> list2 = new ArrayList<>();
|
|
|
+ for (BCourseBusPo bCourseBusPo : list3 ) {
|
|
|
+ String busId = bCourseBusPo.getBusId();
|
|
|
+ BBusInfoPo bBusInfoPo = collect.get(busId);
|
|
|
+ if(bBusInfoPo != null) {
|
|
|
+ BCourseBusDto bCourseBusDto = new BCourseBusDto();
|
|
|
+ bCourseBusDto.setId(bCourseBusPo.getId());
|
|
|
+ bCourseBusDto.setBusId(bCourseBusPo.getBusId());
|
|
|
+ bCourseBusDto.setSort(bCourseBusPo.getSort());
|
|
|
+ bCourseBusDto.setRemark(bCourseBusPo.getRemark());
|
|
|
+ bCourseBusDto.setBusNo(bBusInfoPo.getBusNo());
|
|
|
+ bCourseBusDto.setDriverName(bBusInfoPo.getDriverName());
|
|
|
+ bCourseBusDto.setDriverPhone(bBusInfoPo.getDriverPhone());
|
|
|
+ list2.add(bCourseBusDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bCourseInfoDto.setBCourseBusList(list2);
|
|
|
+ }
|
|
|
return bCourseInfoDto;
|
|
|
}
|
|
|
|
|
|
@@ -98,6 +147,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void save(BCourseInfoDto dto){
|
|
|
BCourseInfoPo po = BeanUtil.toBean(dto, BCourseInfoPo.class);
|
|
|
+ List<BCoursePointDto> mapPointList = dto.getMapPointList();
|
|
|
+ if(CollectionUtil.isNotEmpty(mapPointList)) {
|
|
|
+ String mapPoint = JSONUtil.toJsonStr(mapPointList);
|
|
|
+ po.setMapPoint(mapPoint);
|
|
|
+ }
|
|
|
ExtInfo extInfo = CurrentUserHolder.get();
|
|
|
po.setId(snowflakeUtil.snowflakeId());
|
|
|
po.setCreateTime(new Date());
|
|
|
@@ -108,8 +162,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
po.setUpdaterName(extInfo.getUserName());
|
|
|
//处理时刻
|
|
|
List<BCourseTimeDto> bCourseTimeList = dto.getBCourseTimeList();
|
|
|
- List<BCourseTimePo> bCourseTimePoList = BeanUtil.copyToList(bCourseTimeList, BCourseTimePo.class);
|
|
|
- bCourseTimePoList.forEach(bCourseTimePo -> {
|
|
|
+ po.setFirstBusSpace(bCourseTimeList.get(0).getBusSpace());
|
|
|
+ List<BCourseTimePo> bCourseTimePoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < bCourseTimeList.size(); i++) {
|
|
|
+ BCourseTimeDto bCourseTimeDto = bCourseTimeList.get(i);
|
|
|
+ BCourseTimePo bCourseTimePo = BeanUtil.toBean(bCourseTimeDto, BCourseTimePo.class);
|
|
|
bCourseTimePo.setId(snowflakeUtil.snowflakeId());
|
|
|
bCourseTimePo.setCourseId(po.getId());
|
|
|
bCourseTimePo.setCreateTime(new Date());
|
|
|
@@ -118,12 +175,31 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseTimePo.setUpdaterId(extInfo.getUserId());
|
|
|
bCourseTimePo.setCreatorName(extInfo.getUserName());
|
|
|
bCourseTimePo.setUpdaterName(extInfo.getUserName());
|
|
|
- });
|
|
|
+ if (i == 0) {
|
|
|
+ bCourseTimePo.setType("0");
|
|
|
+ }else {
|
|
|
+ bCourseTimePo.setType("1");
|
|
|
+ }
|
|
|
+ bCourseTimePoList.add(bCourseTimePo);
|
|
|
+ }
|
|
|
bCourseTimeService.saveBatch(bCourseTimePoList);
|
|
|
//处理标志点
|
|
|
List<BCourseStationDto> bCourseStationList = dto.getBCourseStationList();
|
|
|
- List<BCourseStationPo> bCourseStationPoList = BeanUtil.copyToList(bCourseStationList, BCourseStationPo.class);
|
|
|
- bCourseStationPoList.forEach(bCourseStationPo -> {
|
|
|
+
|
|
|
+ String stationId = bCourseStationList.get(0).getStationId();
|
|
|
+ BStationInfoPo byId = bStationInfoService.getById(stationId);
|
|
|
+ po.setFirstStationName(byId.getName());
|
|
|
+ po.setFirstStationId(stationId);
|
|
|
+
|
|
|
+ String stationId1 = bCourseStationList.get(bCourseStationList.size()-1).getStationId();
|
|
|
+ BStationInfoPo byId1 = bStationInfoService.getById(stationId1);
|
|
|
+ po.setLastStationName(byId1.getName());
|
|
|
+ po.setLastStationId(stationId1);
|
|
|
+
|
|
|
+ List<BCourseStationPo> bCourseStationPoList =new ArrayList<>();
|
|
|
+ for(int i = 0; i < bCourseStationList.size(); i++) {
|
|
|
+ BCourseStationDto bCourseStationDto = bCourseStationList.get(i);
|
|
|
+ BCourseStationPo bCourseStationPo = BeanUtil.toBean(bCourseStationDto, BCourseStationPo.class);
|
|
|
bCourseStationPo.setId(snowflakeUtil.snowflakeId());
|
|
|
bCourseStationPo.setCourseId(po.getId());
|
|
|
bCourseStationPo.setCreateTime(new Date());
|
|
|
@@ -132,7 +208,15 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseStationPo.setUpdaterId(extInfo.getUserId());
|
|
|
bCourseStationPo.setCreatorName(extInfo.getUserName());
|
|
|
bCourseStationPo.setUpdaterName(extInfo.getUserName());
|
|
|
- });
|
|
|
+ if (i == 0) {
|
|
|
+ bCourseStationPo.setType("0");
|
|
|
+ }else if(i == bCourseStationList.size()-1) {
|
|
|
+ bCourseStationPo.setType("2");
|
|
|
+ }else{
|
|
|
+ bCourseStationPo.setType("1");
|
|
|
+ }
|
|
|
+ bCourseStationPoList.add(bCourseStationPo);
|
|
|
+ }
|
|
|
bCourseStationService.saveBatch(bCourseStationPoList);
|
|
|
//处理车辆
|
|
|
List<BCourseBusDto> bCourseBusList = dto.getBCourseBusList();
|
|
|
@@ -147,6 +231,7 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseBusPo.setCreatorName(extInfo.getUserName());
|
|
|
bCourseBusPo.setUpdaterName(extInfo.getUserName());
|
|
|
});
|
|
|
+ bCourseBusService.saveBatch(bCourseBusPoList);
|
|
|
this.bCourseInfoMapper.insert(po);
|
|
|
}
|
|
|
|
|
|
@@ -168,6 +253,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
@Override
|
|
|
public void update(BCourseInfoDto dto){
|
|
|
BCourseInfoPo po = BeanUtil.toBean(dto, BCourseInfoPo.class);
|
|
|
+ List<BCoursePointDto> mapPointList = dto.getMapPointList();
|
|
|
+ if(CollectionUtil.isNotEmpty(mapPointList)) {
|
|
|
+ String mapPoint = JSONUtil.toJsonStr(mapPointList);
|
|
|
+ po.setMapPoint(mapPoint);
|
|
|
+ }
|
|
|
ExtInfo extInfo = CurrentUserHolder.get();
|
|
|
po.setUpdateTime(new Date());
|
|
|
po.setUpdaterId(extInfo.getUserId());
|
|
|
@@ -175,8 +265,11 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
//处理时刻
|
|
|
bCourseTimeService.deleteByCourseId(po.getId());
|
|
|
List<BCourseTimeDto> bCourseTimeList = dto.getBCourseTimeList();
|
|
|
- List<BCourseTimePo> bCourseTimePoList = BeanUtil.copyToList(bCourseTimeList, BCourseTimePo.class);
|
|
|
- bCourseTimePoList.forEach(bCourseTimePo -> {
|
|
|
+ po.setFirstBusSpace(bCourseTimeList.get(0).getBusSpace());
|
|
|
+ List<BCourseTimePo> bCourseTimePoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < bCourseTimeList.size(); i++) {
|
|
|
+ BCourseTimeDto bCourseTimeDto = bCourseTimeList.get(i);
|
|
|
+ BCourseTimePo bCourseTimePo = BeanUtil.toBean(bCourseTimeDto, BCourseTimePo.class);
|
|
|
bCourseTimePo.setId(snowflakeUtil.snowflakeId());
|
|
|
bCourseTimePo.setCourseId(po.getId());
|
|
|
bCourseTimePo.setCreateTime(new Date());
|
|
|
@@ -185,13 +278,26 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseTimePo.setUpdaterId(extInfo.getUserId());
|
|
|
bCourseTimePo.setCreatorName(extInfo.getUserName());
|
|
|
bCourseTimePo.setUpdaterName(extInfo.getUserName());
|
|
|
- });
|
|
|
+ if (i == 0) {
|
|
|
+ bCourseTimePo.setType("0");
|
|
|
+ }else {
|
|
|
+ bCourseTimePo.setType("1");
|
|
|
+ }
|
|
|
+ bCourseTimePoList.add(bCourseTimePo);
|
|
|
+ }
|
|
|
bCourseTimeService.saveBatch(bCourseTimePoList);
|
|
|
//处理标志点
|
|
|
bCourseStationService.deleteByCourseId(po.getId());
|
|
|
List<BCourseStationDto> bCourseStationList = dto.getBCourseStationList();
|
|
|
- List<BCourseStationPo> bCourseStationPoList = BeanUtil.copyToList(bCourseStationList, BCourseStationPo.class);
|
|
|
- bCourseStationPoList.forEach(bCourseStationPo -> {
|
|
|
+ String stationName= bCourseStationList.get(0).getName();
|
|
|
+ po.setFirstStationName(stationName);
|
|
|
+ String stationName1 = bCourseStationList.get(bCourseStationList.size()-1).getName();
|
|
|
+ po.setLastStationName(stationName1);
|
|
|
+
|
|
|
+ List<BCourseStationPo> bCourseStationPoList =new ArrayList<>();
|
|
|
+ for(int i = 0; i < bCourseStationList.size(); i++) {
|
|
|
+ BCourseStationDto bCourseStationDto = bCourseStationList.get(i);
|
|
|
+ BCourseStationPo bCourseStationPo = BeanUtil.toBean(bCourseStationDto, BCourseStationPo.class);
|
|
|
bCourseStationPo.setId(snowflakeUtil.snowflakeId());
|
|
|
bCourseStationPo.setCourseId(po.getId());
|
|
|
bCourseStationPo.setCreateTime(new Date());
|
|
|
@@ -200,7 +306,15 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseStationPo.setUpdaterId(extInfo.getUserId());
|
|
|
bCourseStationPo.setCreatorName(extInfo.getUserName());
|
|
|
bCourseStationPo.setUpdaterName(extInfo.getUserName());
|
|
|
- });
|
|
|
+ if (i == 0) {
|
|
|
+ bCourseStationPo.setType("0");
|
|
|
+ }else if(i == bCourseStationList.size()-1) {
|
|
|
+ bCourseStationPo.setType("2");
|
|
|
+ }else{
|
|
|
+ bCourseStationPo.setType("1");
|
|
|
+ }
|
|
|
+ bCourseStationPoList.add(bCourseStationPo);
|
|
|
+ }
|
|
|
bCourseStationService.saveBatch(bCourseStationPoList);
|
|
|
//处理车辆
|
|
|
bCourseBusService.deleteByCourseId(po.getId());
|
|
|
@@ -239,4 +353,96 @@ public class BCourseInfoServiceImpl extends ServiceImpl<BCourseInfoMapper, BCour
|
|
|
bCourseBusService.remove(queryWrapper2);
|
|
|
bCourseInfoMapper.deleteById(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<BBusTrackInfoDto> getNearbyRoutes(BigDecimal latitude, BigDecimal longitude, Integer radius) {
|
|
|
+ // 1. 查询附近站点
|
|
|
+ List<BStationInfoDto> nearbyStations = bCourseInfoMapper.findNearbyStations(latitude, longitude, radius);
|
|
|
+ if (CollectionUtil.isEmpty(nearbyStations)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ // 2. 查询经过这些站点的路线
|
|
|
+ List<Long> stationIds = nearbyStations.stream()
|
|
|
+ .map(BStationInfoDto::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<BCourseInfoVo> routes = bCourseInfoMapper.findRoutesByStations(stationIds);
|
|
|
+
|
|
|
+ for (BCourseInfoVo route : routes) {
|
|
|
+ BBusTrackInfoDto dto = new BBusTrackInfoDto();
|
|
|
+ // vo.setRouteId(route.getId());
|
|
|
+// vo.setRouteName(route.getName());
|
|
|
+// vo.setStartStation(route.getStartStation());
|
|
|
+// vo.setEndStation(route.getEndStation());
|
|
|
+// vo.setFirstTime(route.getFirstTime());
|
|
|
+// vo.setLastTime(route.getLastTime());
|
|
|
+// vo.setPrice(route.getPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+// // 3. 转换并返回结果
|
|
|
+// return routes.stream().map(route -> {
|
|
|
+// RouteVO vo = new RouteVO();
|
|
|
+// vo.setRouteId(route.getId());
|
|
|
+// vo.setRouteName(route.getName());
|
|
|
+// vo.setStartStation(route.getStartStation());
|
|
|
+// vo.setEndStation(route.getEndStation());
|
|
|
+// vo.setFirstTime(route.getFirstTime());
|
|
|
+// vo.setLastTime(route.getLastTime());
|
|
|
+// vo.setPrice(route.getPrice());
|
|
|
+// // 计算距离最近的站点
|
|
|
+// StationDTO nearestStation = findNearestStation(
|
|
|
+// nearbyStations,
|
|
|
+// latitude,
|
|
|
+// longitude
|
|
|
+// );
|
|
|
+// vo.setNearestStation(nearestStation.getName());
|
|
|
+// vo.setDistance(calculateDistance(
|
|
|
+// latitude,
|
|
|
+// longitude,
|
|
|
+// nearestStation.getLatitude(),
|
|
|
+// nearestStation.getLongitude()
|
|
|
+// ));
|
|
|
+// return vo;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查找最近的站点
|
|
|
+ */
|
|
|
+ private BStationInfoDto findNearestStation(
|
|
|
+ List<BStationInfoDto> stations,
|
|
|
+ Double latitude,
|
|
|
+ Double longitude) {
|
|
|
+ return stations.stream()
|
|
|
+ .min(Comparator.comparingDouble(station ->
|
|
|
+ calculateDistance(
|
|
|
+ latitude,
|
|
|
+ longitude,
|
|
|
+ station.getLatitude().doubleValue(),
|
|
|
+ station.getLongitude().doubleValue()
|
|
|
+ )
|
|
|
+ ))
|
|
|
+ .orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算两点之间的距离(米)
|
|
|
+ */
|
|
|
+ private double calculateDistance(
|
|
|
+ Double lat1,
|
|
|
+ Double lng1,
|
|
|
+ Double lat2,
|
|
|
+ Double lng2) {
|
|
|
+ double radLat1 = Math.toRadians(lat1);
|
|
|
+ double radLat2 = Math.toRadians(lat2);
|
|
|
+ double a = radLat1 - radLat2;
|
|
|
+ double b = Math.toRadians(lng1) - Math.toRadians(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 * 6378137; // 地球半径
|
|
|
+ return s;
|
|
|
+ }
|
|
|
}
|