public double borderDistance(double lat,double lon){
  double nsdistance;
  double ewdistance;
  if (south <= lat && lat <= north) {
    nsdistance=0;
  }
 else {
    nsdistance=Math.min((Math.abs(lat - north)),(Math.abs(lat - south)));
  }
  if (west <= lon && lon <= east) {
    ewdistance=0;
  }
 else {
    ewdistance=Math.min((Math.abs(lon - east)),(Math.abs(lon - west)));
  }
  return Math.sqrt(Math.pow(nsdistance,2.0) + Math.pow(ewdistance,2.0));
}

public double borderDistance ( double lat , double lon ) { double nsdistance ; double ewdistance ; if ( south <= lat && lat <= north ) { nsdistance = 0 ; } else { nsdistance = Math . min ( ( Math . abs ( lat - north ) ) , ( Math . abs ( lat - south ) ) ) ; } if ( west <= lon && lon <= east ) { ewdistance = 0 ; } else { ewdistance = Math . min ( ( Math . abs ( lon - east ) ) , ( Math . abs ( lon - west ) ) ) ; } return Math . sqrt ( Math . pow ( nsdistance , 2.0 ) + Math . pow ( ewdistance , 2.0 ) ) ; }
a utility method to figure out the closest distance of a border to a point . if the point is inside the rectangle , return 0 .
