// calculates initial course between two airports given through airport ID's // values from database class methods must be in radians as this is what is used here public static double calcCourBwAir(String id1, String id2) { double cord1[] = FPCDatabase.accsAir(id1); double cord2[] = FPCDatabase.accsAir(id2); double lat1 = cord1[0]; double lat2 = cord2[0]; double longD = cord2[1] - cord1[1]; // longD is the difference of longitude 2 - longitude 1 double y = Math.sin(longD) * Math.cos(lat2); double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(longD); return Math.atan2(y, x); }
// calculates flying distance between the two airports that are given through ID's // values from database class methods must be in radians as this is what is used here public static double calcFlyDis(String id1, String id2) { double r = 6371; // this is KM which means the distance is returned in KM double cord1[] = FPCDatabase.accsAir(id1); double cord2[] = FPCDatabase.accsAir(id2); double lat1 = cord1[0]; double lat2 = cord2[0]; double latD = lat2 - lat1; double longD = cord2[1] - cord1[1]; // longD is the difference of longitude 2 - longitude 1 double a = Math.sin(latD / 2) * Math.sin(latD / 2) + Math.sin(longD / 2) * Math.sin(longD / 2) * Math.cos(lat1) * Math.cos(lat2); return r * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // call the superclass version setContentView(R.layout.flyingdistancecoursepage); // set the layout // get list of ids from database class ArrayList<?> idArray = FPCDatabase.getAirID(); // returning the array list from database class to then get values ids = new String[idArray.size()]; for (int i = 0; i < idArray.size(); i++) { ids[i] = (String) idArray.get( i); // taking every id from the arraylist in the database and adding it to the // string array ids } // Creating adapter with the string array ids and adding it to spinner ArrayAdapter<String> adapterAirports = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ids); ArrayAdapter<CharSequence> adapterUnits = ArrayAdapter.createFromResource( this, R.array.distance_units, android.R.layout.simple_spinner_item); airportOne = (Spinner) findViewById(R.id.flyingdistancecourseDepartingAirportSpinner); airportTwo = (Spinner) findViewById(R.id.flyingdistanceDestinationAirportSpinner); distanceUnits = (Spinner) findViewById(R.id.flyingdistancecourseDistanceUnitSpinner); // Displays the string array for the spinners airportOne.setAdapter(adapterAirports); airportTwo.setAdapter(adapterAirports); distanceUnits.setAdapter(adapterUnits); airportOne.setOnItemSelectedListener(new airportOneSelectedListener()); airportTwo.setOnItemSelectedListener(new airportTwoSelectedListener()); distanceUnits.setOnItemSelectedListener(new distanceUnitSelectedListener()); }