Solved

Format value of decimel to latitude/longitude

Posted on 2006-07-21
11
404 Views
Last Modified: 2012-05-05
Hi I need to format a decimel value example    -34.1605774  to a latitude/longitude format of    DDMMSS S Please Help
0
Comment
Question by:mixmates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 14

Expert Comment

by:StillUnAware
ID: 17156356
What do You mean by that  DDMMSS S?
0
 

Author Comment

by:mixmates
ID: 17156416
DD = Decimel Degrees    MM = Minutes   SS = Seconds S = South the minus at the beginning of that double would represent South a plus would represent North Depending on lat long a plus can be North or East a minus South or West
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17156488
can u eplain the question bit more?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:mixmates
ID: 17156573
I'll try:

in a text field I enter a set of coordinates 470255N 1253755W. These are taken as a string and turned into a double 47.0255 and -125.3755 I need to be able to take it from one format to the other. The coordinates being a string turned into a double and a double into a string with a positive denoting a North minus denoting a South on the first set of numbers and positive denoting East on the second set with a negative denoting west. Mostly I need help going from string to double and back
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17156644
Is this homework?
0
 

Author Comment

by:mixmates
ID: 17156694
No I am new to Java admittedly but I are no longer student I am greduated ; ) I am switching to programming after years of being a sysadmin
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 17156737
try this,

String val = textField.getText() ;

char c = val.charAt( va.length() - 1 ) ;

int divider = 10000 ;
double dval = Double.parseDouble( val.subString( 0, va.length() - 2 ) ) ;
dval = c == 'N' ? ( dval / devider ) : ( -1 * dval/devider ) ;

pls correct if any syntax err
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 17156822
This may be simplified but you could do

    static class Sexagesimal {
      private int seconds;
      private int minutes;
      private int degrees;

      public void setSeconds(int seconds) {
              this.seconds = seconds;
      }

      public int getSeconds() {
            return seconds;
      }

      public void setMinutes(int minutes) {
            this.minutes = minutes;
      }

      public int getMinutes() {
            return minutes;
      }

          public void setDegrees(int degrees) {
                this.degrees = degrees;
          }

          public int getDegrees() {
                return degrees;
          }
          
          public String toString() {
                return new StringBuffer()
                      .append(degrees)
                      .append("\u00B0")
                      .append(" ")
                      .append(minutes)
                      .append("'")
                      .append(" ")
                      .append(seconds)
                      .append("''")
                      .toString();
          }

    }
   
public static Sexagesimal decimalDegreesToSexagesimal(double degrees) {
      Sexagesimal result = new Sexagesimal();
      String whole = Double.toString(degrees);
      String d = whole.substring(0, whole.indexOf("."));
      String dec = whole.substring(whole.indexOf("."));
      result.setDegrees(Integer.parseInt(d));
      double D = Double.parseDouble(dec) * 60.0;
      whole = Double.toString(D);
      d = whole.substring(0, whole.indexOf("."));
      result.setMinutes(Integer.parseInt(d));
      dec = whole.substring(whole.indexOf("."));
      result.setSeconds((int)(Double.parseDouble(dec) * 60.0));
      return result;
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17156827
-34° 9' 38''

is the result given for your example
0
 

Author Comment

by:mixmates
ID: 17157065
Thanks so much for everyones help
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17157076
:-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question