Solved

Format value of decimel to latitude/longitude

Posted on 2006-07-21
11
397 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

734 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