-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocation.java
More file actions
33 lines (25 loc) · 1.13 KB
/
Copy pathLocation.java
File metadata and controls
33 lines (25 loc) · 1.13 KB
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
public class Location {
private final double latitude;
private final double longitude;
public Location(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public double latitude() { return latitude; }
public double longitude() { return longitude; }
public boolean equals(Location that) {
if (that.latitude() == this.latitude() && that.longitude() == this.longitude()) return true;
else return false;
}
public boolean interval(Location loc1, Location loc2) {
if (latitude >= loc1.latitude() && latitude <= loc2.latitude() && longitude >= loc1.longitude() && longitude <= loc2.longitude()) return true;
return false;
}
// calculo da distância, aproximando a região por um plano (em kilometros);
public double distance(Location that){
return (Math.sqrt(Math.pow((this.latitude - that.latitude), 2) + Math.pow((this.longitude - that.longitude), 2)))*1852*0.06;
}
public String toString() {
return ("latitude: " + this.latitude + " longitude: " + this.longitude);
}
}