Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

Latitude to decimal degrees.

Thread view: 
bherbst65@hotmail.com - 26 Nov 2005 17:32 GMT
Hi All,

I have a this code to grab the  input global latitude reading and
change it to a degree decimal reading.
......... code snip........

public void actionPerformed(ActionEvent event)  {
     //calculations below
     flocdegree = Double.parseDouble(tf1.getText());
     flocmin =  Double.parseDouble(tf2.getText())/60;
     flocsec = Double.parseDouble(tf3.getText())/3600;
     flocdegree = flocdegree + flocmin + flocsec;
     locdir1=  tf4.getText();
     System.out.println(locdir1);
     if (locdir1.equals("S") )
       flocdegree = -1* flocdegree;
     if (locdir1.equals("W") )
       flocdegree = -1* flocdegree;
     DecimalFormat df = new DecimalFormat("#.#####");
       tf5.setText(df.format(flocdegree));
   }
........... end of snip........

Is there a more direct process so as to  require less code to implement
the change?
I have looked at Roedy's glossary of alpha terms and there was no
references
to latitude, longitude.

TIA

Bob
Roedy Green - 26 Nov 2005 21:43 GMT
> if (locdir1.equals("S") )
>        flocdegree = -1* flocdegree;
i would write that as
         flocDegree = -flocDegree;

There is no need to multiply when all you need is a sign inversion.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 26 Nov 2005 21:48 GMT
>if (locdir1.equals("S") )
>        flocdegree = -1* flocdegree;
>      if (locdir1.equals("W") )
>        flocdegree = -1* flocdegree;
this strikes me as a bit odd. This same code is gathering a latitude
OR a longitude?

What about 'w' and 's'?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 26 Nov 2005 22:41 GMT
>I have looked at Roedy's glossary of alpha terms and there was no
>references
>to latitude, longitude.

see http://mindprod.com/jgloss/latitude.html
http://mindprod.com/jgloss/longitude.html

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

bherbst65@hotmail.com - 27 Nov 2005 00:36 GMT
Roedy,

This ship above  was a combined (latitude or longitude) calculation. I
needed this to deal with data that was shown such as Los Angeles County

34:04:45N 118:24:05W    to the another form  34.07917   -118.40139

Here is the complete code below (at this time). While not shown here
will be features: name the location, radio buttons to detail whether it
is a latitude or a longitude, and the combining of  the statements,
then a button to save as an append to a file.

This is output is used in another program to show the global (planet
Earth) distances between locations as the crow flies (ugh!), but which
lacks the MapQuest accuracy.

Bob

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

public class Frame3 extends JFrame  {

 private JButton calcBtn = new JButton();
 private JButton ClearDataBtn = new JButton();

 String locdir1;
 double  flocdegree , flocmin, flocsec;
 String Dir ;

 Label lble1     = new Label ("Convert Degrs, Mins, Secs and  Dir " );
 Label lble6    =  new Label ("Degrees as a Integer" );
 Label lble7    = new Label ("Minutes as a Integer");
 Label lble8    = new Label ("Seconds as a Integer");
 Label lble9  = new Label (" Direction (N/S or E/W)");
 Label lble10  = new Label ("Converted Value");

 TextField tf1  = new TextField(10);//Degrees
 TextField tf2  = new TextField(10);//Minutes
 TextField tf3  = new TextField(10);//Seconds
 TextField tf4  = new TextField(10);//Direction N/S or E/W
 TextField tf5  = new TextField(20);//Resultant Value

 static void main() {
   Frame3 fr3= new Frame3();
   fr3.setVisible(true);  // replaces depreciated version 1.1 was
fr2.show();
 }

 Frame3() {
   setSize(300, 300);
   add(lble1);

   setLayout(new FlowLayout());
   add(lble6);
   add(tf1); // degrees

   add(lble7);
   add(tf2); // minutes

   add(lble8);
   add(tf3); // seconds

   add(lble9);
   add(tf4);// a Direction letter

   calcBtn.setText("           Do Calculations             ");
   add(calcBtn);
   add(lble10);
   add(tf5);

   calcBtn.addActionListener(new CalcData());
   add(tf5);

   ClearDataBtn.setText("Clear");
   ClearDataBtn.addActionListener(new ClearData());
   add(ClearDataBtn);
 }

 class CalcData implements ActionListener {
   public void actionPerformed(ActionEvent event)  {
     //calculations below
     flocdegree = Double.parseDouble(tf1.getText());
     flocmin =  Double.parseDouble(tf2.getText())/60;
     flocsec = Double.parseDouble(tf3.getText())/3600;
     flocdegree = flocdegree + flocmin + flocsec;
     locdir1=  tf4.getText();
     System.out.println(locdir1);
     if (locdir1.equals("S") )
       flocdegree = -1* flocdegree;
     if (locdir1.equals("W") )
       flocdegree = -1* flocdegree;
     DecimalFormat df = new DecimalFormat("#.#####");
       tf5.setText(df.format(flocdegree));
   }
 }
class ClearData implements ActionListener {
   public void actionPerformed(ActionEvent event)  {
     tf1.setText("");
     tf2.setText("");
     tf3.setText("");
     tf4.setText("");
     tf5.setText("");
   }
}
 //Overridden so we can exit when window is closed
 protected void processWindowEvent(WindowEvent e) {
   super.processWindowEvent(e);
   if (e.getID() == WindowEvent.WINDOW_CLOSING) {
     System.exit(0);
   }
 }
}
Roedy Green - 27 Nov 2005 00:59 GMT
> TextField tf1  = new TextField(10);//Degrees
>  TextField tf2  = new TextField(10);//Minutes
>  TextField tf3  = new TextField(10);//Seconds
>  TextField tf4  = new TextField(10);//Direction N/S or E/W
>  TextField tf5  = new TextField(20);//Resultant Value

Name your fields meaningfully e.g. degrees,   directionNSEW,
fractionalDegrees. Use of arbitrary names will guarantee bug
introduction.

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

bherbst65@hotmail.com - 27 Nov 2005 03:05 GMT
Hi Roedy,

Will  make the changes. Still did not get an answer to my Q..... Are
there Java terms   to change a (degree, minute, second)  to a degree
decimal reading  other than the way written above? I suppose that there
is not,  since you have not indicated it.

Thanks for your insight and response.

Bob
Roedy Green - 27 Nov 2005 06:13 GMT
>Will  make the changes. Still did not get an answer to my Q..... Are
>there Java terms   to change a (degree, minute, second)  to a degree
>decimal reading  other than the way written above? I suppose that there
>is not,  since you have not indicated it.

The best code I know is at http://mindprod.com/jgloss/latitude.html
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.