Page 457 - 2
P. 457

}
                              if(location == null || l.getAccuracy() < location.getAccuracy()){
                                 location = l;
                              }
                          }
                          return location;
                       }


                   }
                   private double distance(double lat1, double lon1, double lat2, double lon2, String unit) {

                       double theta = lon1 - lon2;
                       double dist = Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2)) + Math.cos(deg2rad(lat1)) * Math.
            cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));

                       dist = Math.acos(dist);
                       dist = rad2deg(dist);
                       dist = dist * 60 * 1.1515;


                       if (unit == "kilometer") {
                          dist = dist * 1.609344;
                       } else if (unit == "meter") {
                          dist = dist * 1609.344;
                       }
                       return (dist);
                   }




                   // This function converts decimal degrees to radians
                   private double deg2rad(double deg) {
                       return (deg * Math.PI / 180.0);
                   }


                   // This function converts radians to decimal degrees
                   private double rad2deg(double rad) {
                       return (rad * 180 / Math.PI);
                   }


               }
               Handler handler = new Handler() {
                   @Override
                   public void handleMessage(Message msg) {
                       super.handleMessage(msg);
                       switch (msg.what) {
                          case TOAST_MESSAGE:
                              Toast.makeText(getApplicationContext(), (String) msg.obj, Toast.LENGTH_SHORT).show();
                              break;
                          case Image_driving:
                              imageView.setImageResource(R.drawable.image_driving);
                              break;


                                                         - 457 -
   452   453   454   455   456   457   458   459   460   461   462