Solved

Format value of decimel to latitude/longitude

Posted on 2006-07-21
11
380 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
  • 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

823 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