long start=System.nanoTime();
...
연산
...
long end=System.nanoTime();
double elapsed=(end-start)/1000000.0;
4710.8095
@Override
public LocationResponseDTO testJavaLocation(LocationRequestDTO locationRequestDTO) {
long start=System.nanoTime();
List<Shop> shopList=shopRepository.findAll();
double myLat=locationRequestDTO.getLatitude();
double myLng=locationRequestDTO.getLongitude();
List<ShopResponseDTO> shopDTO=new ArrayList<>();
for(Shop shop:shopList){
double shopLat=shop.getLatitude();
double shopLng=shop.getLongitude();
double theta = myLng - shopLng;
double dist = Math.sin((myLat * Math.PI/180.0))* Math.sin((shopLat * Math.PI/180.0))
+ Math.cos((myLat * Math.PI/180.0))*Math.cos((shopLat * Math.PI/180.0))*Math.cos((theta * Math.PI/180.0));
dist = Math.acos(dist);
dist = (dist * 180 / Math.PI);
dist = dist * 60*1.1515*1609.344;
shopDTO.add(
ShopResponseDTO.builder()
.shopName(shop.getName())
.address(shop.getAddress())
.latitude(shop.getLatitude())
.longitude(shop.getLongitude())
.distance(dist)
.build()
);
}
Collections.sort(shopDTO);
long end=System.nanoTime();
double time=(end-start)/1000000.0;
LocationResponseDTO dto=LocationResponseDTO.builder()
.shop(shopDTO)
.time(time)
.build();
return dto;
}

Mysql 좌표 거리계산, JPA, nativeQuery 를 이용한 거리계산