Need some help!

Posts 1–10 of 10 · Page 1 of 1
Need some help!
I'm trying to make a longitude and latitude converter. I use Google maps to get longitude and latitude for my handheld GPS but there longitude and latitude is a different type then my GPS uses. I have to convert it before putting it in my GPS. I made a very simple program using VB 2008 that open up right to Google maps and at the top of the program i want to put the converter. I have done a lot of research and still i am not able to wright a code that will do the conversion. For the conversion Need to multiply the decimal part of the longitude and latitude by 60
For example if i had 40.313043,-97.573244 I would multiply .313043 by 60 witch = 18.78258 and then i would multiply .573244 by 60 witch = 34.39464
The finale longitude and latitude would be 40 18.782, 97 34.394
If anyone could help me wright a code to do this or give me a few tips it would be much appreciated
You weren't exactly clear on what to do with the part you multiply by 60, it looks like you just appended it with a space?

Code:
Private Shared Function CorrectInput(ByVal arg As Double) As String
    Dim dec As Double = 60 * (arg - (arg \ 1))
    Return (arg \ 1).ToString() + " " + dec.ToString()
End Function
Example:

Code:
Dim raw As Double = 40.313043
MessageBox.Show(CorrectInput(raw))
'messagebox will popup "40 18.75258"
Why does it convert a negative number to a positive number?
Quote Originally Posted by Jason View Post
Why does it convert a negative number to a positive number?
It converts it to a positive number because because its going from a Latitude/Longitude that uses degrees to a Latitude/Longitude that uses north, south, east, and west
Alright so something like:

Code:
    Private Function ConvertValue(ByVal arg As Double) As String
        arg = Math.Abs(arg)
        Dim intval As Integer = CType(Math.Floor(arg), Integer)
        Return intval.ToString() + " " + (60 * (arg - intval)).ToString()
    End Function
Should do the job?
Code:
Public Class Form1

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Url = New Uri("http://maps.google.com/?ie=UTF8&t=h&vpsrc=0&ll=37.09024,-95.712891&spn=33.435463,56.25/")
    End Sub
    Private Function ConvertValue(ByVal arg As Double) As String
        arg = Math.Abs(arg)
        Dim Latitude As Integer = CType(Math.Floor(arg), Integer)
        Return Latitude.ToString() + " " + (60 * (arg - Latitude)).ToString()
    End Function
    Private Function ConvertValue2(ByVal arg As Double) As String
        arg = Math.Abs(arg)
        Dim Longitude As Integer = CType(Math.Floor(arg), Integer)
        Return Longitude.ToString() + " " + (60 * (arg - Longitude)).ToString()
    End Function
OK this what I have and i think i got it right but how do I get the results from ConvertValue and ConvertValue2 to show up in text boxes or labels
You don't need to create the function twice with different names:

Code:
Private Function ConvertValue(ByVal arg As Double) As String
    arg = Math.Abs(arg)
    Dim intval As Integer = CType(Math.Floor(arg), Integer)
    Return intval.ToString() + " " + (60 * (arg - intval)).ToString()
End Function

Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
    TextBox1.Text = ConvertValue(47.343924) 
    TextBox2.Text = ConvertValue(-97.323132)
End Sub
I changed it from a Latitude/Longitude textbox to a text box for Latitude and one for Longitude. So wouldn't i need the function twice? Also with
Code:
TextBox1.Text = ConvertValue(47.343924) 
    TextBox2.Text = ConvertValue(-97.323132)
it will always come up with 47.3439924 and -97.323132.
what i want it to do is the conversion for what ever i put in the textbox1 and textbox2 and i want the converted Latitude/Longitude to end up in textbox3 textbox4
I know, use some initiative and change 47/-97 to some textbox values or something, I can't do EVERYTHING for you.
Posts 1–10 of 10 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us