Solved

Format value of decimel to latitude/longitude

Posted on 2006-07-21
11
359 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoresSpecial  challenge 13 42
countX 22 71
wordappend challenge 8 88
JDeveloper 12c for 32 bit 4 36
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now