Results 1 to 1 of 1

Thread: Convert Distance - Latitude program to a mapping distance program

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Location
    NB, Canada
    Posts
    52

    Arrow Convert Distance - Latitude program to a mapping distance program

    Hi,

    I've found this code that makes the breakdown between 2 distances using Google Maps.

    What I want is, with the 2 distances inserted the action-Button open IE, Opera, Firefox, Whatever ... and in this window, Google Maps show the mapping distance from adress 1 to adress 2 automatically.

    Thank you

    Code:
    Option Strict Off
    Option Explicit On
    Imports VB = Microsoft.VisualBasic
    Friend Class GEOStuffForm
    	Inherits System.Windows.Forms.Form
    	Private Sub AskGoogleButton_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles AskGoogleButton.Click
    		Dim Lon As String
    		Dim Lat As String
    		Dim Comma As Object
    		Dim LC As Object
    		Dim GC2 As Object
    		Dim GC As Object
    		Dim a As String
    		Dim GoogleWebPage As String
    		Dim WebURL As String
    		Dim i As Object
    		On Error GoTo BolloxedData
    		'===========
    		'CLEAR STUFF
    		'===========
    		Latitude(1).Text = "" : Latitude(2).Text = ""
    		Longitude(1).Text = "" : Longitude(2).Text = ""
    		System.Windows.Forms.Application.DoEvents()
    		'==========================================
    		'CHECK IF USER FILLED IN THE ADDRESS FIELDS
    		'==========================================
    		If MissingData Then
    			MsgBox("Please fill in the form correctly.", MsgBoxStyle.ApplicationModal + MsgBoxStyle.Exclamation, "Whoops!")
    			Exit Sub
    		End If
    		AskGoogleButton.Enabled = False
    		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
    		System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    		Dim NotFound As Boolean
    		For i = 1 To 2
    			NotFound = True
    			WebURL = "http://maps.google.com/maps?q="
    			WebURL = WebURL & Trim(Street(i).Text) & ",+"
    			WebURL = WebURL & Trim(City(i).Text) & ",+"
    			WebURL = WebURL & Trim(State(i).Text) & ",+"
    			WebURL = WebURL & Trim(Zip(i).Text)
    			WebURL = Replace(WebURL, " ", "+")
    			GoogleWebPage = GetUrlSource(WebURL)
    			a = LCase(GoogleWebPage)
    			'=======================================================
    			'EXTRACT THE LATITUDE AND LONGITUDE FROM GOOGLE WEB PAGE
    			'=======================================================
    			'UPGRADE_WARNING: Couldn't resolve default property of object GC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    			GC = InStr(a, ":{lat:") + 2
    			'UPGRADE_WARNING: Couldn't resolve default property of object GC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    			If GC > 2 Then
    				'UPGRADE_WARNING: Couldn't resolve default property of object GC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				'UPGRADE_WARNING: Couldn't resolve default property of object GC2. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				GC2 = InStr(GC, a, "},")
    				'UPGRADE_WARNING: Couldn't resolve default property of object GC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				'UPGRADE_WARNING: Couldn't resolve default property of object GC2. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				'UPGRADE_WARNING: Couldn't resolve default property of object LC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				LC = GC2 - GC
    				'UPGRADE_WARNING: Couldn't resolve default property of object LC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    				If LC > 20 And LC < 200 Then
    					'UPGRADE_WARNING: Couldn't resolve default property of object LC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    					'UPGRADE_WARNING: Couldn't resolve default property of object GC. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    					a = Mid(a, GC + 4, LC - 6)
    					'UPGRADE_WARNING: Couldn't resolve default property of object Comma. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    					Comma = InStr(a, ",")
    					'UPGRADE_WARNING: Couldn't resolve default property of object Comma. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    					If Comma Then
    						'UPGRADE_WARNING: Couldn't resolve default property of object Comma. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    						Lat = VB.Left(a, Comma - 1) & New String(Chr(48), 12)
    						Lat = VB.Left(Lat, 12)
    						'UPGRADE_WARNING: Couldn't resolve default property of object Comma. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
    						Lon = VB.Right(a, Len(a) - (Comma + 4)) & New String(Chr(48), 12)
    						Lon = VB.Left(Lon, 12)
    						If System.Math.Abs(Val(Lat)) > 0 And System.Math.Abs(Val(Lon)) > 0 Then
    							Latitude(i).Text = Lat
    							Longitude(i).Text = Lon
    							NotFound = False
    						End If
    					End If
    				End If
    			End If
    			System.Windows.Forms.Application.DoEvents()
    		Next i
    ReturnResult: 
    		'UPGRADE_ISSUE: Constant Default was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="55B59875-9A95-4B71-9D6A-7C294BF7139D"'
    		'UPGRADE_ISSUE: Screen property Screen.MousePointer does not support custom mousepointers. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="45116EAB-7060-405E-8ABE-9DBB40DC2E86"'
    		'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6BA9B8D2-2A32-4B6E-8D36-44949974A5B4"'
            System.Windows.Forms.Cursor.Current = Cursors.Default
    		If NotFound Then
    			MsgBox("NO MAP COORDINATES HAVE BEEN FOUND!", MsgBoxStyle.ApplicationModal + MsgBoxStyle.Exclamation, "ADDRESS???")
    			Beep()
    		Else ' Watch for my next upgrade - ok? (Dinner's waiting)
    			'============================================================================
    			'Why not put some MORE FUN into this and calculate the distance between them?
    			'============================================================================
    		End If
    		AskGoogleButton.Enabled = True
    		Exit Sub
    BolloxedData: 
    		NotFound = True
    		Resume ReturnResult
    	End Sub
    	Function MissingData() As Boolean
    		Dim i As Object
    		For i = 1 To 2
    			If Trim(State(i).Text) = "" Or Trim(Zip(i).Text) = "" Then
    				MissingData = True
    				Exit For
    			End If
    		Next i
    	End Function
    
        Private Sub GEOStuffForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    End Class
    Last edited by hackedman; May 25th, 2010 at 09:41 PM. Reason: Editing code from the click button

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width