```
Sub Process_Globals
Private DegreesSDRoation As Float
Private SDFunction As Int
Private Azimuth1, Elevation1, SolarOffSet, SolarABOffSet As Double
End Sub
#Region Sundial
Sub BtnSunDial_click
VibBip
If SDFunction = 0 Then
SunDialOn
Else
SunDialOff
End If
End Sub
Sub SunDialOn
SDFunction = 1
IVSun.Visible = True
IVShadowLine.Visible = True
IVShadowLine.BringToFront
IVSun.BringToFront
SolarBearing1
'UpDate Displays
SolarOffSet = Abs(Azimuth1 - AntBearing) Mod 360
SolarOffSet = Min(360-SolarOffSet, SolarOffSet)
SolarABOffSet = Abs(Azimuth1 - ABearing) Mod 360
SolarABOffSet = Min(360 - SolarABOffSet, SolarABOffSet)
lblASolarOffsetNNN.Text = NumberFormat2 (SolarABOffSet, 1 , 1, 1, False)
lblSolarOffsetNNN.Text = NumberFormat2 (SolarOffSet, 1 , 1, 1, False)
lblSolarAzimuthNNN.Text = NumberFormat2 (Azimuth1, 1 , 1, 1, False)
lblASolarAzimuthNNN.Text = NumberFormat2 (Azimuth1, 1 , 1, 1, False)
lblSolarElevationNNN.Text = NumberFormat2 (Elevation1, 1 , 1, 1, False)
lblASolarElevationNNN.Text = NumberFormat2 (Elevation1, 1 , 1, 1, False)
If Mode = 0 Then
lblSolarOffsetNNN.Visible = True
lblSolarOffset.Visible = True
lblSolarAzimuth.Visible = True
lblSolarAzimuthNNN.Visible = True
lblSolarElevation.Visible = True
lblSolarElevationNNN.Visible = True
Else If Mode = 1 Then
lblASolarOffsetNNN.Visible = True
lblASolarOffset.Visible = True
lblASolarAzimuth.Visible = True
lblASolarAzimuthNNN.Visible = True
lblASolarElevation.Visible = True
lblASolarElevationNNN.Visible = True
End If
End Sub
Sub SunDialOff
SDFunction = 0
IVSun.Visible = False
IVShadowLine.Visible = False
lblSolarOffsetNNN.Visible = False
lblSolarOffset.Visible = False
lblSolarAzimuthNNN.Visible = False
lblSolarAzimuth.Visible = False
lblSolarElevation.Visible = False
lblSolarElevationNNN.Visible = False
lblASolarOffsetNNN.Visible = False
lblASolarOffset.Visible = False
lblASolarAzimuth.Visible = False
lblASolarAzimuthNNN.Visible = False
lblASolarElevation.Visible = False
lblASolarElevationNNN.Visible = False
If Mode = 0 Then cp.Initialize2(MapLat, MapLng, MapZoom, 0, 0 ) 'Zero map
If Mode = 1 Then cp.Initialize2(ABMapLat, ABMapLng, ABMapZoom, 0, 0 ) 'Zero map
gmap.AnimateCamera(cp)
End Sub
Sub SunAndShadow
'Position Sun and Shadow
If Mode = 0 Then
IVSun.Top = pnlDispLatLng.Height + 2dip
IVSun.Left = BTSIV.Left - 2.5dip
IVShadowLine.Height = BTSIV.Top - pnlDispLatLng.Height - IVSun.Height
End If
If Mode = 1 Then
IVSun.Top = pnlABDispLatLng.Height + 2dip
IVSun.Left = AEndIV.Left - 2.5dip
IVShadowLine.Height = AEndIV.Top - pnlABDispLatLng.Height - IVSun.Height
End If
IVShadowLine.Top = IVSun.Top + IVSun.Height
IVShadowLine.Left = IVSun.Left + 11.5dip
End Sub
Sub SolarBearing1
Private Mylocation1 As LatLng
Private twopi As Double = 2*cPI
Private rad As Double = cPI/180
Private dEarthMeanRadius As Double = 6371.01 ' In km
Private dAstronomicalUnit As Double = 149597890 ' In km
Private dElapsedJulianDays, dDecimalHours, dEclipticLongitude, dEclipticObliquity, dSin_EclipticLongitude As Double
Private dRightAscension, dDeclination, dDeclination, dJulianDate, Longitude1, Latitude1 As Double
Private dx,dy, dMeanLongitude, dMeanAnomaly, dOmega, dGreenwichMeanSiderealTime, dLocalMeanSiderealTime As Double
Private dLatitudeInRadians, dHourAngle, dCos_Latitude, dSin_Latitude, dCos_HourAngle, dParallax, dZenithAngle As Double
Private liAux1, liAux2, tnow As Long
'Find current location
Mylocation1 = gmap.MyLocation
Latitude1 = Mylocation1.Latitude
Longitude1 = Mylocation1.Longitude
If Abs(Latitude1) > 24 Then 'Inaccurate at latitudes close to the equator
''Position Sun and Shadow
SunAndShadow
' Calculate difference In days between the current Julian Day
' AND JD 2451545.0, which Is noon 1 January 2000 Universal Time
' // Calculate time of the day In UT decimal hours
' tnow = DateTime.Now
tnow = DateTime.Now - DateTime.TimeZoneOffset * DateTime.TicksPerHour
dDecimalHours = DateTime.GetHour(tnow) + DateTime.GetMinute(tnow)/60 _
+ DateTime.GetSecond(tnow)/3600
' Calculate current Julian Day
liAux1 = (DateTime.GetMonth(tnow)-14)/12
liAux2 = (1461*(DateTime.GetYear(tnow) + 4800 + liAux1)) / 4 + (367 * (DateTime.GetMonth(tnow) _
- 2 -12*liAux1)) / 12- (3 * ((DateTime.GetYear(tnow) + 4900 _
+ liAux1) / 100)) / 4 + DateTime.GetDayOfMonth(tnow) - 32075
dJulianDate = liAux2 - 0.5 + dDecimalHours / 24.0
' // Calculate difference between current Julian Day AND JD 2451545.0
dElapsedJulianDays = dJulianDate - 2451545.0
' Calculate ecliptic coordinates (ecliptic longitude AND obliquity of the
' ecliptic In radians but without limiting the angle To be less than 2*Pi
' (i.e., the result may be greater than 2*Pi)
dOmega = 2.1429 - 0.0010394594 * dElapsedJulianDays
dMeanLongitude = 4.8950630 + 0.017202791698 * dElapsedJulianDays ' Radians
dMeanAnomaly = 6.2400600 + 0.0172019699 * dElapsedJulianDays
dEclipticLongitude = dMeanLongitude + 0.03341607 * Sin( dMeanAnomaly ) _
+ 0.00034894 * Sin( 2*dMeanAnomaly ) - 0.0001134 _
- 0.0000203*Sin(dOmega)
dEclipticObliquity = 0.4090928 - 6.2140e-9 * dElapsedJulianDays _
+ 0.0000396 * Cos(dOmega)
' Calculate celestial coordinates ( right ascension AND declination ) In radians
' but without limiting the angle To be less than 2*Pi (i.e., the result may be
' greater than 2*Pi)
dSin_EclipticLongitude = Sin( dEclipticLongitude )
dy = Cos( dEclipticObliquity ) * dSin_EclipticLongitude
dx = Cos( dEclipticLongitude )
dRightAscension = ATan2( dy,dx )
If ( dRightAscension < 0.0 ) Then dRightAscension = dRightAscension + twopi
dDeclination = ASin( Sin( dEclipticObliquity ) * dSin_EclipticLongitude )
' Calculate local coordinates ( azimuth AND zenith angle ) In degrees
dGreenwichMeanSiderealTime = 6.6974243242 + 0.0657098283 * dElapsedJulianDays + dDecimalHours
dLocalMeanSiderealTime = (dGreenwichMeanSiderealTime * 15 + Longitude1) * rad
dHourAngle = dLocalMeanSiderealTime - dRightAscension
dLatitudeInRadians = Latitude1 * rad
dCos_Latitude = Cos( dLatitudeInRadians )
dSin_Latitude = Sin( dLatitudeInRadians )
dCos_HourAngle= Cos( dHourAngle )
dZenithAngle = (ACos( dCos_Latitude * dCos_HourAngle * Cos(dDeclination) + _
Sin( dDeclination )* dSin_Latitude))
dy = -Sin( dHourAngle )
dx = Tan( dDeclination )* dCos_Latitude - dSin_Latitude * dCos_HourAngle
Azimuth1 = ATan2( dy, dx )
If Azimuth1< 0.0 Then Azimuth1 = Azimuth1 + twopi
Azimuth1 = Azimuth1/rad
' // Parallax Correction
dParallax = (dEarthMeanRadius/dAstronomicalUnit) * Sin(dZenithAngle)
dZenithAngle = (dZenithAngle + dParallax)/rad
Elevation1 = 90 - dZenithAngle
' Rotate Map
DegreesSDRoation = Azimuth1
If Mode = 0 Then
cp.Initialize2(MapLat, MapLng, MapZoom, 0, 0 ) 'Zero map
cp.Initialize2(MapLat, MapLng, MapZoom, DegreesSDRoation, 0 ) 'Rotate map
End If
If Mode = 1 Then
cp.Initialize2(ABMapLat, ABMapLng, ABMapZoom, 0, 0 ) 'Zero map
cp.Initialize2(ABMapLat, ABMapLng, ABMapZoom, DegreesSDRoation, 0 ) 'Rotate map
End If
gmap.AnimateCamera(cp)
Else
ToastMessageShow ( "Unavailable at this Latitude.", True)
SunDialOff
End If
End Sub
#End Region
```