Calculating GPS latitude/longitude from NMEA strings

It has long bugged me that the cgps tool shows accurate position data (longitude and latitude) that doesn't match the NMEA strings at all.
For example, suppose that the NMEA string values for a position are as follows:
3218.0489, N, 6447.5086, W
In the code examples we provided in the MOOC, we simply divided the double value of the string by 100, thinking the NMEA strings are decimal degree values.
However, plug 32.180489 N and 64.475086 W into Google maps and you end up some where in the Atlantic ocean.  Well, that's not right!
As it turns out, the NMEA strings are decimal-decimal values.  In order to turn them into decimal degree values, you have to do some math:
32 18.0489 N = 32 degrees + 18.0489 / 60 = 32.300815 N
64 47.5086 W = 64 degrees + 47.5086 / 60 = 64.79181 W
Plug those values into Google maps, and voila!  The real location is on the island of Bermuda.
Now, you may also want to represent the values using degrees/minutes/seconds. The math to do that is fairly simple:
32.300815 = 32 degrees
.300815 * 60 = 18.0489 = 18 minutes
.0489 * 60 = 2.934 seconds
Which can be written as: 32° 18' 2.9"
Here's the code to convert the NMEA decimal-decimal values to degrees/minutes/seconds:
     * Convert a NMEA decimal-decimal degree value into degrees/minutes/seconds
     * First. convert the decimal-decimal value to a decimal:
     * 5144.3855 (ddmm.mmmm) = 51 44.3855 = 51 + 44.3855/60 = 51.7397583 degrees
     * Then convert the decimal to degrees, minutes seconds:
     * 51 degress + .7397583 * 60 = 44.385498 = 44 minutes
     * .385498 = 23.1 seconds
     * Result: 51 44' 23.1"
     * @return String value of the decimal degree, using the proper units
    private String decimalToDMS(double value) {
        String result = null;
        double degValue = value / 100;
        int degrees = (int) degValue;
        double decMinutesSeconds = ((degValue - degrees)) / .60;
        double minuteValue = decMinutesSeconds * 60;
        int minutes = (int) minuteValue;
        double secsValue = (minuteValue - minutes) * 60;
        result = degrees + "\u00B0" + " " + minutes + "' " + String.format("%.1f", secsValue) + "\" ";
        return result;
Enjoy!
Tom

Thanks for the information. :)
Now I was stuck at how to use the string I read from file to create url.
the url look like this: http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/2.314594,102.319944/17?pp=2.315515,%20102.319998;;UTeM&key=AtF15nTCNXcfudToKct4rzBxIwmJfnUVTkt5RaOd47rO-qt8bql30WRWIpN1AdVk
Theoretically we can call the gps coordinate from text file into the url using following method:
string key = "YOUR_BING_MAPS_KEY";
string query = "1 Microsoft Way, Redmond, WA"; 
Uri geocodeRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", query, key)); 
Response r = await GetResponse(geocodeRequest);     //Add logic to process response data string results = r.ResourceSets[0].Resources.Length.ToString() + " result(s) found.";  
Somehow I still haven't found a method to utilize the method.

Similar Messages

  • Converting from UTM meter to latitude,longitude in oracle

    I am trying to write a procedure which takes in utm data and converts to latitude,longitude
    mostly on the net i am getting some formulas for conversion with no proper explanation.
    Can any of you suggest any previously written oracle procedure or other help.
    UTM data is available in a column, i convert the data into lat,long and take the lat
    from easting in deg,minustes,seconds and likewise longitude from northing.
    there are some methods like using excel or in java, but i want to do it in Oracle.
    Please help as i am looking for suggestions and help.

    Hi,
    you should ask in the SPATIAL forum. This is a spatial conversion and Oracle has functions for these. In the SPATIAL forum there are the experts (I'm not).
    See Spatial
    Herald ten Dam
    http://htendam.wordpress.com

  • Is there an easy way to convert from a String with a comma, ie. 1,000.00 to

    Is there an easy way to convert from a String with a comma, ie. 1,000.00 to a float or a double?
    thanks,
    dosteov

    Like DrClap said: DecimalFormat. However, make sure you understand the Locale things, as explained at http://java.sun.com/j2se/1.3/docs/api/java/text/DecimalFormat.html (which refers to NumberFormat as well) and use them explicitly. Like
    public class FormatTest
      public static void main(String args[])
        try
          // see NumberFormat.getInstance()
          DecimalFormat fmt = new DecimalFormat();
          Number num = fmt.parse("1,000.01");
          System.out.println(num.doubleValue());
        catch(ParseException pe)
          System.out.println(pe);
    }most likely seems OK on your system, but may print "1.0" (or even fail) on some non-English platforms!
    When performing calculations, also see http://developer.java.sun.com/developer/JDCTechTips/2001/tt0807.html
    a.

  • Latitude/Longitude on Oracle Locator

    Hi, I'm using Oracle Locator
    I'm trying to select latitude and longitude through this query
    SELECT t.X AS LATITUDE, t.Y AS LONGITUDE
    FROM geo.cultura c,
    TABLE(SDO_UTIL.GETVERTICES(c.geometry)) t;
    but the numbers are coming from different 90 and -90
    A example: X=343819,495658682 and Y=7382918,56758273
    Is there a command to convert those numbers?
    Thank you very much!

    Hi,
    SDO_UTIL.GETVERTICES returns the coordinates of the vertices of the geometry. If your coordinate system is other than geodetic coordinates then you need transformation.
    For example
    SELECT t.X AS LATITUDE, t.Y AS LONGITUDE
    FROM spl_major_villages c,
    TABLE(SDO_UTIL.GETVERTICES(SDO_CS.TRANSFORM(c.geom, 0.005, 8307))) t;
    Sujnan

  • CONVERTING X,Y TO LATITUDE,LONGITUDE VICE VERSA

    hi,
    i need formula for converting x,y coordinates to latitude ,longitude and vice versa,
    CAN ANYBODY HELP ME IN THIS?

    There is no standard formula for such conversions, as converting from one coordinate system to another is often a complex mathematical formula. What you need to do is track down (via the internet) the mathematical formula you require for your conversion and then apply that formula as SQL or PL/SQL code. You can pretty much do any mathematics in Oracle code, but firstly you need to know the maths required (and so would we if you expect us to help you).

  • Replacing a set of characters from a string in oracle sql query

    I want to replace a set of characters ( ~    !     @    #     $     %     ^     *     /     \     +    :    ;    |     <     >     ?    _  ,) from a STRING in sql
    select 'TESTING ! ABC 123 #'
    FROM DUAL;
    What is the best way to do it? Please provide examples also.

    What is your expected output... The query I posted just removes them, it never replaces them with spaces..your string already has space.. if you want to remove space as well .. try this...
    SELECT TRANSLATE ('TESTING ! ABC 123 #', '-~!@#$%^*/\+:;|<>?_, ', ' ') FROM DUAL;
    Output:
    --TESTINGABC123
    Else post your expected output..
    Cheers,
    Manik.

  • Problems with Reflection API and intantiating an class from a string value

    I want to instantiate a class with the name from a String. I have used the reflection api so:
    static Object createObject(String className) {
    Object object = null;
    try {
    Class classDefinition = Class.forName(className);
    object = classDefinition.newInstance();
    } catch (InstantiationException e) {
    System.out.println(e);
    } catch (IllegalAccessException e) {
    System.out.println(e);
    } catch (ClassNotFoundException e) {
    System.out.println(e);
    return object;
    Let's say my class name is "Frame1".
    and then if i use:
    Frame1 frm = (Frame1) createObject("Frame1");
    everything is ok but i cannot do this because the name "Frame1" is a String variable called "name" and it doesn't work like:
    name frm = (name) createObject("Frame1");
    where i'm i mistaking?
    Thanks very much!

    i have understood what you have told me but here is a little problem
    here is how my test code looks like
    Class[] parameterTypes = new Class[] {String.class};
    Object frm = createObject("Frame1");
    Class cls = frm.getClass();
    cls.getMethod("pack",parameterTypes);
    cls.getMethod("validate",parameterTypes);
    everything works ok till now.
    usually if i would of had instantiated the "Frame1" class standardly the "cls" (or "frm" in the first question ) object would be an java.awt.Window object so now i can't use the function (proprietary):
    frame_pos_size.frame_pos_size(frm,true);
    this function requires as parameters: frame_pos_size(java.awt.Window, boolean)
    because my cls or frm objects are not java.awt.Window i really don't find any solution for my problem. I hope you have understood my problem. Please help. Thanks a lot in advance.

  • How can i store values from my String into Array

    Hi guys
    i wants to store all the values from my string into an array,,,, after converting them into intergers,,,, how i can do this becs i have a peice of code which just give me a value of a character at time,,,,charat(2)...BUT i want to the values from String to store in an Array
    here is my peice of code which i m using for 1 char at time
    int[] ExampleArray2 = new int[24];
    String tempci = "Battle of Midway";
    for(int i=0;i>=tempci.length();i++)
    int ascii = tempci.charAt(i); //Get ascii value for the first character.

    public class d1
         public static final void main( String args[] )
              int[] ExampleArray2 = new int[24];
              String tempci = "Battle of Midway";
              for(int i=0;i<tempci.length();i++)
                   int ascii = tempci.charAt(i);
                   ExampleArray2=ascii;
              for(int i=0;i<ExampleArray2.length;i++)
                   System.out.println(ExampleArray2[i]);

  • Getting char values from a string problem

    Hi,
    Here's an example of what I'm trying to do:
    boolean loopSwitch = true;
    while (loopSwitch)
         String orderDecider = JOptionPane.showInputDialog (null, "Would you like your numbers to be ordered in   ascending or descending order(A/D)",      "Order decision", JOptionPane.QUESTION_MESSAGE);
         if (orderDecider == A)
         loopSwitch = false;
         }I basically want the user to input either a/A/d/D and to get the char values from the string so I can use them in an if statement.
    Basically, I wanna parse the string into a char.
    Is this possible?
    Thanks.
    Edited by: xcd on Oct 16, 2009 8:38 AM

    Why not just use the String.equals() method to compare a String to a String?
    But if you must, you can use the String.charAt() method to return a char at a particular location in the String.
    Note: char literals need to be surrounded by single quotes ('A') and String literals need to be surrounded by double quotes ("A").

  • Removing Null values from character string

    Hi All,
    Can i remove NULL values (hexadecimal - 0000) from character string. I am uploading a file from presentation layer (shared server) and getting NULL values in many fields which i want to remove.
    please assist.
    Thanks for you help..
    Regards,
    Mohaiyuddin

    Hi,
    Most likely, nobody needed it, but if anybody in future will need the solution for related problem  - here's solution:
    data: lv_nullchar type xstring value '0'.
    shift lv_xstring right deleting trailing lv_nullchar in byte mode.
    shift lv_xstring left deleting leading lv_nullchar in byte mode.
    This hack deleting null chars in lv_xstring at end file and at begining of file. Works perfect for me, where i also worked with files.

  • How to get the Values i need from a String???

    hi i need some help on my program,
    I have a Server that actually sent some data to my Client.
    The data consist of some messages and intergers . The whole piece of data is stores as a String message.
    ARRAY 'Monitor Chart' 2 5
    'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'''
    0.0 1.0 2.0 3.0 4.0
    'Series1' 11.0 0.6 8.6 11.5 6.6
    'Series2' 12.8 6.7 21.6 11.1 30.0Inside the Client i need to get the values out to showed on my textfields
    Example :
    Tf1 = 11.0
    Tf2 = 0.6
    Tf3 = 8.6
    Tf4 = 11.5
    Tf5 = 6.6
    Question: How to i get the values out from the String???

    using the split() method. i am able to split everything now
    so it appear somthing like this :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class testing{
         String d1 =     "ARRAY 'Monitor Chart' 1 5";
         String d2 = "'Total OverFlow' 'Queued' 'Completed' 'Host Resets' 'Errors'";
         String d3 = "'' 0.0 1.0 2.0 3.0 4.0 ";
         String d4 = "'Series1' 11.0 0.6 8.6 11.5 6.6 ";
         String d5 = "'Series2' 12.8 6.7 21.6 11.1 30.0 ";
         String data = d1 + d2 + d3 + d4 + d5;     
         public testing(){
              System.out.println(data);
              String[] result = data.split("\\s");
              for(int x=0;x<result.length;x++)
              System.out.println(result[x]);
         public static void main (String args[])throws IOException{
            testing Application = new testing();
    }ARRAY
    'Monitor
    Chart'
    2
    5
    'Total OverFlow'
    'Queued'
    'Completed'
    'Host Resets'
    'Errors'''
    0.0
    1.0
    2.0
    3.0
    4.0
    'Series1'
    11.0
    0.6
    8.6
    11.5
    6.6
    'Series2'
    12.8
    6.7
    21.6
    11.1
    30.0
    but how do i get the values out ??how do i noe it is which index or wad?
    11.0
    0.6
    8.6
    11.5
    6.6

  • Escape single quote from a String variable

    Hi,
    I have a String variable called "name" which i am using in my form tag.
    <form name=test action="test.jsp?fname=<%=name%>" method="post">
    But i am getting Javascript error if the "name" variable contains a string with some special characters like single quote( ' ).
    Plz help me to escape this special char from my String variable.
    Thanks..

    You need to url-encode the value using the URLEncoder class.
    http://java.sun.com/javase/6/docs/api/java/net/URLEncoder.html
    For example:
    <form name=test action="test.jsp?fname=<%=URLEncoder.encode(name, "ISO-8859-1")%>" method="post">

  • How do I make a Datagram Packet from a String?

    I am looking to make a Datagram Packet from a string. If I send a command to a server that allows remote connections via UDP, such as "restart" it will restart the server. I can accomplish this easily through the fput() method of PHP.
    I want a Java version of my utility, and am using the DatagramSocket and DatagramPacket classes. I see that I need to make a byte array and put it inside a DatagramPacket. How would I go about putting the string "restart" into a byte array?
    Thanks,

    Use the following code to send a Datagram:-
    import java.io.*;
    import java.net.*;
    // This class sends the specified text as a datagram to port 6010 of the
    // specified host.
    public class UDPSend {
        static final int port = 6010;
        public static void main(String args[]) throws Exception {
            if (args.length != 2) {
                System.out.println("Usage: java UDPSend <hostname> <message>");
                System.exit(0);
            // Get the internet address of the specified host
            InetAddress address = InetAddress.getByName(args[0]);
            // Convert the message to an array of bytes
            int msglen = args[1].length();
            byte[] message = new byte[msglen];
            args[1].getBytes(0, msglen, message, 0);
            // Initilize the packet with data and address
            DatagramPacket packet = new DatagramPacket(message, msglen,
                                   address, port);
            // Create a socket, and send the packet through it.
            DatagramSocket socket = new DatagramSocket();
            socket.send(packet);
    }This uses argments, if you want a string change the code accordingly.

  • Can you create an object from a string

    I have been working on creating a dynamic form, creating the
    form items from an xml file. I am getting very close to conquering
    this task. I will share it when it's complete.
    However, I am stuck at the moment trying to create an object
    from a string. For example, if the xml item is an HBox I want to
    create an HBox. Like this: parentObject = new arrayOfFormItems[
    index ]..type ()
    This isn't working. First, is this possible using some syntax
    I am unaware of in Flex? I don't want to use a large if or case
    statement if possible.
    Thanks in advance for your help!

    Thank you very much. Indeed that did solve the one problem. I
    missed the casting as a Display Object. That is awesome!
    I do still however, have to instantiate one of every item I
    want to dynamically create or I get the following error when I try
    to create a dynamic object that I have not instantiated before.
    ReferenceError: Error #1065: Variable HBox is not defined.
    at global/flash.utils::getDefinitionByName()
    at MyForm/buildForm()
    at DynamicForm/::onComplete()
    at
    flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/flash.net:URLLoader::onComplete()
    I read that you have no choice but to instantiate one of each
    type to force the linker to link the code for that class into the
    .swf. Unless you know another way to force it.
    This is what I have in my Application mxml to get it to work:
    <mx:HBox>
    <mx:Text visible="false"/>
    <mx:TextArea visible="false"/>
    <mx:TextInput visible="false"/>
    <mx:DateField visible="false"/>
    </mx:HBox>
    And those are the types I'm using to test with. . . I will
    have to add all the others I want to use as well . . .

  • Retrieve data from a string.

    I want to write a SQL script to retreive data between the third "|" and the forth "|" from a string:
    Example:
    String = 'H000319|VI|12|20000|20000|4201840007403429,09/2008,442667,,|'
    The result should be 20000.
    String = 'H000319|HK|0|11860|11860||'
    The result should be 11860.
    Many thanks!

    With INSTR you can search for the n'th occurence of a character like this:
    select substr('H000319|HK|0|11860|11860||'
                 , instr('H000319|HK|0|11860|11860||', '|', 1, 3 ) + 1
                 , length('H000319|HK|0|11860|11860||') - instr('H000319|HK|0|11860|11860||', '|', 1, 4 ) - 2
                ) from dual

Maybe you are looking for

  • UTF-8 encoding not working in MSIE

    We're in the process of migrating to Sun Web Server 6.1 2005Q4 SP5 from iPlanet 4.1. The Unicode encoding in JSPs for special characters rendered correctly in browsers with iPlanet 4.1. But in 6.1, I had to add this directive to obj.conf for it to wo

  • Why won't my IMAC recognize my new smart phone via USB?

    Why won't my imac recognize my new smart phone via USB?

  • Dynamic Drop-down list - selected value can't be cleared ...

    1. check out the following code of a dynamic drop down list using cursor :- DECLARE      -- DROP-DOWN LIST OF ALL DEPARTMENTS      TEMPNUMBER NUMBER(2) := 2 ; -- Because we've to initialize the list -- at least with 1 item. CURSOR C_DEPT IS      SELE

  • 4s white and black with different brightness?

    By comparison, found the same brightness, two machines have shown that color differences, black feeling is darker, is normal or not?

  • Mail says it cannot find reply??

    On my Exchange account, when I hit the arrow indicating a relied message, an error message pops up telling me that Mail cannot find the reply, that I may have deleted it. However, the replies are sitting in my sent mail folder. These are messages tha