original_docstring: Calculates the latitude and longitude for the center of a grid square.
  If two grid squares are given, the distance and azimuth between them is calculated.
docstring: Calculates the latitude and longitude for the center of a grid square.
  If two grid squares are given, the distance and azimuth between them is calculated.
docstring_tokens: Calculates the latitude and longitude for the center of a grid square . If two grid squares are given the distance and azimuth between them is calculated .
code: async def loc(ctx, grid : str, grid2 : str = None):
      '''Calculates the latitude and longitude for the center of a grid square.
  If two grid squares are given, the distance and azimuth between them is calculated.'''
      with ctx.typing():
          if grid2 is None or grid2 == '':
              try:
                  grid = grid.upper()
                  loc = getCoords(grid)
  
                  if len(grid) >= 6:
                      embed = discord.Embed(title=f'Latitude and Longitude for {grid}',
                              description=f'**{loc[0]:.5f}, {loc[1]:.5f}**', colour=green,
                              url=f'https://www.openstreetmap.org/#map=13/{loc[0]:.5f}/{loc[1]:.5f}')
  
                  else:
                      embed = discord.Embed(title=f'Latitude and Longitude for {grid}',
                              description=f'**{loc[0]:.1f}, {loc[1]:.1f}**', colour=green,
                              url=f'https://www.openstreetmap.org/#map=10/{loc[0]:.1f}/{loc[1]:.1f}')
              except Exception as e:
                  msg = f'Error generating latitude and longitude for grid {grid}.'
                  embed = discord.Embed(title=msg, description=str(e), colour=red)
          else:
              R = 6371
              try:
                  grid = grid.upper()
                  grid2 = grid2.upper()
                  loc = getCoords(grid)
                  loc2 = getCoords(grid2)
                  # Haversine formula
                  dLat = math.radians(loc2[0] - loc[0])
                  dLon = math.radians(loc2[1] - loc[1])
                  a = math.sin(dLat/2) ** 2 +\
                      math.cos(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) *\
                      math.sin(dLon/2) ** 2
                  c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
                  d = R * c
                  d_mi = 0.6213712 * d
  
                  # Bearing
                  y = math.sin(math.radians(loc2[1]-loc[1])) * math.cos(math.radians(loc2[0]))
                  x = math.cos(math.radians(loc[0])) * math.sin(math.radians(loc2[0])) -\
                      math.sin(math.radians(loc[0])) * math.cos(math.radians(loc2[0])) *\
                      math.cos(math.radians(loc2[1] - loc[1]))
                  bearing = ( math.degrees(math.atan2(y, x)) + 360 ) % 360
  
                  des = f'**Distance:** {d:.1f} km ({d_mi:.1f} mi)\n**Bearing:** {bearing:.1f}°'
                  embed = discord.Embed(title=f'Great Circle Distance and Bearing from {grid} to {grid2}',
                          description=des, colour=green)
              except Exception as e:
                  msg = f'Error generating great circle distance and bearing from {grid} and {grid2}.'
                  embed = discord.Embed(title=msg, description=str(e), colour=red)
      await ctx.send(embed=embed)
code_tokens: async def loc ( ctx , grid : str , grid2 : str = None ) : with ctx . typing ( ) : if grid2 is None or grid2 == '' : try : grid = grid . upper ( ) loc = getCoords ( grid ) if len ( grid ) >= 6 : embed = discord . Embed ( title = f'Latitude and Longitude for {grid}' , description = f'**{loc[0]:.5f}, {loc[1]:.5f}**' , colour = green , url = f'https://www.openstreetmap.org/#map=13/{loc[0]:.5f}/{loc[1]:.5f}' ) else : embed = discord . Embed ( title = f'Latitude and Longitude for {grid}' , description = f'**{loc[0]:.1f}, {loc[1]:.1f}**' , colour = green , url = f'https://www.openstreetmap.org/#map=10/{loc[0]:.1f}/{loc[1]:.1f}' ) except Exception as e : msg = f'Error generating latitude and longitude for grid {grid}.' embed = discord . Embed ( title = msg , description = str ( e ) , colour = red ) else : R = 6371 try : grid = grid . upper ( ) grid2 = grid2 . upper ( ) loc = getCoords ( grid ) loc2 = getCoords ( grid2 ) dLat = math . radians ( loc2 [ 0 ] - loc [ 0 ] ) dLon = math . radians ( loc2 [ 1 ] - loc [ 1 ] ) a = math . sin ( dLat / 2 ) ** 2 + math . cos ( math . radians ( loc [ 0 ] ) ) * math . cos ( math . radians ( loc2 [ 0 ] ) ) * math . sin ( dLon / 2 ) ** 2 c = 2 * math . atan2 ( math . sqrt ( a ) , math . sqrt ( 1 - a ) ) d = R * c d_mi = 0.6213712 * d y = math . sin ( math . radians ( loc2 [ 1 ] - loc [ 1 ] ) ) * math . cos ( math . radians ( loc2 [ 0 ] ) ) x = math . cos ( math . radians ( loc [ 0 ] ) ) * math . sin ( math . radians ( loc2 [ 0 ] ) ) - math . sin ( math . radians ( loc [ 0 ] ) ) * math . cos ( math . radians ( loc2 [ 0 ] ) ) * math . cos ( math . radians ( loc2 [ 1 ] - loc [ 1 ] ) ) bearing = ( math . degrees ( math . atan2 ( y , x ) ) + 360 ) % 360 des = f'**Distance:** {d:.1f} km ({d_mi:.1f} mi)\n**Bearing:** {bearing:.1f}°' embed = discord . Embed ( title = f'Great Circle Distance and Bearing from {grid} to {grid2}' , description = des , colour = green ) except Exception as e : msg = f'Error generating great circle distance and bearing from {grid} and {grid2}.' embed = discord . Embed ( title = msg , description = str ( e ) , colour = red ) await ctx . send ( embed = embed )
short_docstring: Calculates the latitude and longitude for the center of a grid square.
short_docstring_tokens: Calculates the latitude and longitude for the center of a grid square .
comment: '''Calculates the latitude and longitude for the center of a grid square.
  If two grid squares are given, the distance and azimuth between them is calculated.'''$SEP$# Haversine formula$SEP$# Bearing