-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathTransitHandler.java
43 lines (34 loc) · 1.46 KB
/
TransitHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import com.google.common.geometry.*;
public class TransitHandler extends Thread{
private S2LatLng currentLocation;
private S2LatLng destination;
private double distance;
private int secondsToCross;
private GUI gui;
public TransitHandler(S2LatLng currentLocation, S2LatLng destination, GUI gui){
this.currentLocation = currentLocation;
this.destination = destination;
this.gui = gui;
this.distance = S2Wrapper.GreatEarthDistance(this.currentLocation, this.destination);
this.secondsToCross = (int) (distance/5.0); //move at 5m/s
}
public void run(){
try{
int sections = (int) (distance / 5.0);
double startLat = this.currentLocation.latDegrees();
double startLng = this.currentLocation.lngDegrees();
double latChange = (this.destination.latDegrees() - this.currentLocation.latDegrees()) / sections;
double lngChange = (this.destination.lngDegrees() - this.currentLocation.lngDegrees()) / sections;
for(int i = 0; i < sections; i++){
//move a bit
currentLocation = S2LatLng.fromDegrees(startLat + (latChange * i) , startLng + (lngChange * i));
//spawn an update thread
gui.updateLocation(currentLocation);
//sleep(1000)
Thread.sleep(1000);
}
}catch (Exception e) {
System.out.println(e.getMessage());
}
}
}