Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Format value of decimel to latitude/longitude

Posted on 2006-07-21
11
Medium Priority
?
412 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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 2000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

688 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