Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** Coordinates Class
- * v 1.0
- * @author Thibaut Vercueil
- *
- */
- public class Coordinates {
- private double lat;
- private double lng;
- /**
- * Constructor
- * @param lat
- * @param lng
- */
- public Coordinates(double lat, double lng){
- this.lat = lat;
- this.lng = lng;
- }
- /**
- * Getter
- * @return current latitude
- */
- public double getLat(){
- return this.lat;
- }
- /**
- * Getter
- * @return current longitude
- */
- public double getLng(){
- return this.lng;
- }
- /**
- * Setter
- * @param l latitude
- */
- public void setLat(double l){
- this.lat = l;
- }
- /**
- * Setter
- * @param l longitude
- */
- public void setLng(double l){
- this.lng = l;
- }
- public double getDistance(Coordinates C){
- //Converting into Radian
- double phi1 = (this.lat * Math.PI) / 180;
- double lambda1 = (this.lng * Math.PI) / 180;
- double phi2 = (C.getLat() * Math.PI) / 180;
- double lambda2 = (C.getLng() * Math.PI) / 180;
- //Applying the magic formula
- return Math.acos(Math.sin(phi1)*Math.sin(phi2) + Math.cos(phi1)*Math.cos(phi2)*Math.cos(lambda2 - lambda1))*6371000;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement