|
|
Title | Display a map for an address on Google maps or Yahoo maps in the system's default browser in Visual Basic 6 |
Description | This example shows how to display a map for an address on Google maps or Yahoo maps in the system's default browser in Visual Basic 6. |
Keywords | map, address lookup, Google, Yahoo, default browser, VB 6, Visual Basic 6 |
Categories | Internet |
|
|
When the user clicks a button, read the address from a text box and build an appropriate URL to load the map. Then use the ShellExecute API function to launch the URL in the system's default browser.
The following code shows how the program launches Google maps. It uses a very simple method (replaces spaces with "+" and commas with "%2c") to encode the address so it doesn't confuse the browser and inserts the encoded address into the basic map URL. It then checks a combo box to see if it should display a normal, satellite, or terrain map and makes the appropriate substitution. Finally it launches the URL.
|
|
Private Sub cmdGoogle_Click()
' The basic map URL without the address information.
Const URL_BASE As String = _
"http://maps.google.com/maps?f=q&hl=en&geocode=&time=&date=&ttype=&q=@ADDR@&ie=UTF8&t=@TYPE@"
Dim addr As String
Dim url As String
' A very simple URL encoding.
addr = txtAddress.Text
addr = Replace$(addr, " ", "+")
addr = Replace$(addr, ",", "%2c")
' Insert the encoded address into the base URL.
url = Replace$(URL_BASE, "@ADDR@", addr)
' Insert the proper type.
Select Case cboGoogle.Text
Case "Map"
url = Replace$(url, "@TYPE@", "m")
Case "Satellite"
url = Replace$(url, "@TYPE@", "h")
Case "Terrain"
url = Replace$(url, "@TYPE@", "p")
End Select
' "Execute" the URL to make the default browser display
' it.
ShellExecute ByVal 0&, "open", url, _
vbNullString, vbNullString, SW_SHOWMAXIMIZED
End Sub
|
|
The following code performs similar steps for a Yahoo map. It can display a low-bandwidth version, in addition to normal, satellite, and hybrid versions.
|
|
Private Sub cmdYahoo_Click()
' The basic map URL without the address information.
Const URL_FAST As String = _
"http://maps.yahoo.com/broadband#mvt=@TYPE@&q1=@ADDR@"
Const URL_SLOW As String = _
"http://maps.yahoo.com/maps_result.php?q1=@ADDR@"
Dim addr As String
Dim url As String
' Get broadband or dial-up base URL.
If cboYahoo.Text = "Dial-Up" Then
url = URL_SLOW
Else
url = URL_FAST
End If
' A very simple URL encoding.
addr = txtAddress.Text
addr = Replace$(addr, " ", "+")
addr = Replace$(addr, ",", "%2c")
' Insert the encoded address into the base URL.
url = Replace$(url, "@ADDR@", addr)
' Insert the proper type.
Select Case cboGoogle.Text
Case "Map"
url = Replace$(url, "@TYPE@", "m")
Case "Satellite"
url = Replace$(url, "@TYPE@", "s")
Case "Hybrid"
url = Replace$(url, "@TYPE@", "h")
End Select
' "Execute" the URL to make the default browser display
' it.
ShellExecute ByVal 0&, "open", url, _
vbNullString, vbNullString, SW_SHOWMAXIMIZED
End Sub
|
|
|
|
|
|