Public Function ConvertToMap(ByVal lat As Double, ByVal lon As Double, ByVal elev As Double, ByVal layer As ILayer) As IPoint 'Convert x and y to map units. m_pApp is set in ICommand_OnCreate. Dim pMxApp As IMxApplication Dim mapPoint As IPoint Dim pPoint As Point ' = m_mapPoint Dim sMessage As String = "" pMxApp = m_pApp mapPoint = pMxApp.Display.DisplayTransformation.ToMapPoint(0, 0) Dim pSpatialRefFactory As ISpatialReferenceFactory pSpatialRefFactory = New SpatialReferenceEnvironment Dim pGeographicCoordinateSystem As IGeographicCoordinateSystem pGeographicCoordinateSystem = pSpatialRefFactory.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984) pPoint = mapPoint ' Set the Spacial Ref. to WGS 84 pPoint.Project(pGeographicCoordinateSystem) pPoint.X = lon pPoint.Y = lat Dim code As Integer Dim pProjectedCoordinateSystem As IProjectedCoordinateSystem code = pMxApp.Display.DisplayTransformation.SpatialReference.FactoryCode() ' Dont' know if map is in Geographic or Projected coordinate system so try both. Try pProjectedCoordinateSystem = pSpatialRefFactory.CreateProjectedCoordinateSystem(code) pPoint.Project(pProjectedCoordinateSystem) Catch ex As Exception pGeographicCoordinateSystem = pSpatialRefFactory.CreateGeographicCoordinateSystem(code) pPoint.Project(pGeographicCoordinateSystem) End Try Return pPoint End Function
Solved! Go to Solution.
couldn't you just call pPoint.Project(pMxApp.Display.DisplayTransformation.SpatialReference) ?