1 package org.kuali.mobility.bus.service.util;
2
3 import org.kuali.mobility.bus.entity.BusStop;
4
5 public class BusStopDistanceUtil
6 {
7 private static double earthRadius = 6371;
8
9 public BusStopDistanceUtil(){
10
11 }
12
13
14 public double calculateDistance(BusStop s,double lat1,double lon1) {
15 double pk = 180/3.14159;
16
17 double a1 = Double.parseDouble(s.getLatitude()) / pk;
18 double a2 = Double.parseDouble(s.getLongitude()) / pk;
19 double b1 = lat1 / pk;
20 double b2 = lon1 / pk;
21
22 double t1 = Math.cos(a1) * Math.cos(a2) * Math.cos(b1) * Math.cos(b2);
23 double t2 = Math.cos(a1) * Math.sin(a2) * Math.cos(b1) * Math.sin(b2);
24 double t3 = Math.sin(a1) * Math.sin(b1);
25 double tt = Math.acos(t1 + t2 + t3);
26
27 return 6366000*tt;
28
29
30
31
32
33
34
35
36
37
38
39
40 }
41
42 }