This sample tool reports the mouse down location in decimal degrees. To convert decimal degrees to DMS (degrees, minutes, seconds), use the LatLonFormat object.
How to use
- Load some projected data into the focus map.
- Add a new UIToolControl to any toolbar.
- Paste the code into VBA.
- Make sure the names of the controls match, the sample assumes UIToolControl1.
- Completely close VBA so mouse events fire.
- Select the tool and then click anywhere on the focus map.
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
Dim pMxDoc As IMxDocument
Dim pPoint As IPoint
Dim pClone As IClone
Dim pGeometry As IGeometry
Dim pSpatialRefFactory As ISpatialReferenceFactory
Dim pSpatialRef As ISpatialReference
Dim pGeographicCoordSys As IGeographicCoordinateSystem
'Get the point where the user clicked
Set pMxDoc = Application.Document
If pMxDoc.CurrentLocation.IsEmpty Then Exit Sub
'Clone the point because we don't want to alter
'the actual document's current location point
Set pClone = pMxDoc.CurrentLocation
Set pPoint = pClone.Clone
Set pGeometry = pPoint 'QI
'Create a new geographic coordinate system to use in the conversion
Set pSpatialRefFactory = New SpatialReferenceEnvironment
Set pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)
Set pSpatialRef = pGeographicCoordSys 'QI
pSpatialRef.SetFalseOriginAndUnits -180, -90, 1000000
pGeometry.Project pSpatialRef
MsgBox pPoint.x & ", " & pPoint.y, , "Decimal Degrees"
End Sub