Thanks to Bert Granberg who originally posted this on the Utah GIS Portal.
I only made minor changes and added a few different Google/Bing choices.
Nick Harrison. Dec 2009
Part I. Paste code into VBA Editor
1) From the ArcMap menu, navigate to Tools --> Macros --> Visual Basic Editor to open the
VBA editor
2) In the VBA Editor's Project Window, expand either the Normal (Normal.mxt) or the
Project (YourMXDName.mxd) --> Arcmap Objects folder and double click on ThisDocument
Note: If you want the code accessible in every MXD you open place the code in the Normal.mxt;
If you only want it in a specific MXD then place it in the project.
3) Paste the code (below) in the window that opens and close the VBA editor.
4) Save your project
Part II. Create and configure custom ArcMap Tool
1) From the ArcMap menu, navigate to Tools -->Customize
2) Click the Commands tab.
3) Click the drop-down arrow on the Save in combo box, then change the selected item so it is
either the Normal.MXD or the current name of your ArcMap project (ex. Untitled.mxd) depending
on where you placed the code in part I.
4) Click [UIControls] in the Categories list. then Click the New UIControl button.
5) Click the UIToolControl radio button and then click Create.
6) The name of the new tool appears in the Commands list. Single click the newly created UIControl,
then click it again to activate in-place editing, then type a new name for the control so it reads
Normal.GoogleMap_Link or Project.GoogleMap_Link depending on where you put the code.
7) Click and drag the newly created UIControl and drop it on an ArcMap toolbar or menu.
8) With the Customize dialog still open, on the toolbar or menu, right-click the command to set its
image, caption, and other properties.
9) Save Project and start using the tool.
10) To change the specific Google/Bing parameters (i.e. Street View / Bird's Eye, etc) edit the
code in the VBA Editorand change the URL String(s) in case 6 and/or 7. Several options are
available in the code as comments. Or have a look at all the parameters at:
11) Optional Step - If you like this tool and use it a lot then I recommend changing the behaviour
of the mouse wheel in ArcMap so that Roll up/down matches the behaviour of Google/Bing.
By default, ArcMap is the oposite. To change this in ArcMap go to The Tools menu / Options.
On the Genral tab set Mouse Wheel setting to "Zooms In"
------
Option Explicit
Const SW_SHOWMAXIMIZED = 3
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWDEFAULT = 10
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNORMAL = 1
Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal hWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Function OpenLocation(URL As String, WinState As Long) As Long
'PURPOSE: Opens default browser to display URL
'RETURNS: module handle to executed application or
'Error Code ( < 32) if there is an error
'can also be used to open any document associated with
'an application on the system (e.g., passing the name
'of a file with a .doc extension will open that file in Word)
Dim lHWnd As Long
Dim lAns As Long
lAns = ShellExecute(lHWnd, "open", URL, vbNullString, _
vbNullString, WinState)
OpenLocation = lAns
'ALTERNATIVE: if not interested in module handle or error
'code change return value to boolean; then the above line
'becomes:
'OpenLocation = (lAns > 32)
End Function
Private Function GoogleMap_Link_Message() As String
GoogleMap_Link_Message = "Link to Google or Bing Web Map"
End Function
Private Sub GoogleMap_Link_Mousedown(ByVal button As Long, ByVal shift _
As Long, ByVal x As Long, ByVal y As Long)
Dim pMxDoc As IMxDocument
Dim pApp As IMxApplication
Dim pMap As IMap
Dim pPoint As IPoint
Dim pSpatialReferenceFactory As ISpatialReferenceFactory
Dim pSpatialReference As ISpatialReference
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pApp = Application
Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
Set pSpatialReference = pSpatialReferenceFactory. _
CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
' convert mouse click to map units
Set pPoint = pApp.Display.DisplayTransformation.ToMapPoint(x, y)
Set pPoint.SpatialReference = pMap.SpatialReference
If pPoint.SpatialReference.Name > pSpatialReference.Name Then
pPoint.Project pSpatialReference
End If
Dim URLstr As String
Dim returnLong As Long
Dim webmapchoice
webmapchoice = MsgBox("Launch web map application?" & vbCrLf & vbCrLf _
& "Open Map at: " & Round(pPoint.y, 6) & ", " & Round(pPoint.x, 6) & vbCrLf & vbCrLf _
& "Click YES for GOOGLE Maps" & vbCrLf _
& "Click NO for BING Maps" & vbCrLf & vbCrLf _
& "or CANCEL to exit.", vbYesNoCancel, "WEB RESOURCES")
Select Case webmapchoice
Case 6
'GOOGLE MAP - HYBRID
URLstr = " _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) _
& "&z=17&t=h"
Case 7
'BING MAPS - HYBRID
URLstr = " _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&lvl=17&style=h"
Case 2
Exit Sub
End Select
'Use one of the constants as the window state parameter
returnLong = OpenLocation(URLstr, SW_SHOWNORMAL)
' URL CODE FOR OTHER POSSIBILITIES:
'more info on google map URL query string request setting parameters:
'
'more info on BING URL query string request setting parameters:
'
'GOOGLE MAP - HYBRID
'URLstr = " _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) _
& "&z=17&t=h"
'GOOGLE MAP - STREET VIEW
'URLstr = " _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&cbp=1,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&z=17"
'GOOGLE MAP - STREET VIEW WITH MAP - SPLIT SCREEN
'URLstr = " _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&cbp=11,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&t=h&z=17"
'GOOGLE MAP - STREET VIEW WITH MAP - LOWER RIGHT CORNER
'URLstr = " _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&cbp=12,0,,0,5&ll=" _
& Round(pPoint.y, 6) & "," & Round(pPoint.x, 6) & "&t=h&z=17"
'BING MAPS - HYBRID
' URLstr = " _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&lvl=17&style=h"
'BING MAPS - Bird's Eye
'URLstr = " _
& Round(pPoint.y, 6) & "~" & Round(pPoint.x, 6) _
& "&style=o&dir=0"
End Sub
Private Sub GoogleMap_Link_Click()
End Sub
Private Function GoogleMap_Link_ToolTip() As String
GoogleMap_Link_ToolTip = "Google / Bing Map"
End Function