import java.sql.*;

public class GeoCoordJ implements java.sql.SQLData {
  private double latitude, longitude;

  public String getSQLTypeName() {
     return "GEOCOORD";
  }

  public void readSQL(SQLInput stream,String typeName)
    throws SQLException {
      latitude = stream.readDouble();
      longitude = stream.readDouble();
  }

  public void writeSQL(SQLOutput stream)
    throws SQLException {
      stream.writeDouble(latitude);
      stream.writeDouble(longitude);
  }

  public double distance(GeoCoordJ other) {
    return
      6370 *
      Math.acos(
         Math.cos(this.latitude/180*3.14) *
         Math.cos(other.latitude/180*3.14) *
         Math.cos(
          (this.longitude - other.longitude)
             /180*3.14
         ) +
         Math.sin(this.latitude/180*3.14) *
         Math.sin(other.latitude/180*3.14)
      );
  }
}
