0
0
Drone Programmingprogramming~20 mins

GPS coordinate system (latitude, longitude, altitude) in Drone Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GPS Coordinate Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Calculate distance between two GPS points

Given two GPS points with latitude and longitude, what is the output of this code that calculates the approximate distance in kilometers using the Haversine formula?

Drone Programming
from math import radians, sin, cos, sqrt, atan2

def haversine(lat1, lon1, lat2, lon2):
    R = 6371  # Earth radius in km
    dlat = radians(lat2 - lat1)
    dlon = radians(lon2 - lon1)
    a = sin(dlat/2)**2 + cos(radians(lat1)) * cos(radians(lat2)) * sin(dlon/2)**2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    return R * c

point1 = (52.2296756, 21.0122287)
point2 = (41.8919300, 12.5113300)
distance = haversine(*point1, *point2)
print(round(distance, 1))
A879.6
B1317.5
C1150.3
D1420.8
Attempts:
2 left
💡 Hint

Remember the Haversine formula calculates great-circle distance between two points on a sphere.

🧠 Conceptual
intermediate
1:30remaining
Understanding altitude in GPS coordinates

Which statement correctly describes the altitude value in a GPS coordinate system?

AAltitude is the distance from the equator along the Earth's surface.
BAltitude is the height above the Earth's surface at the given latitude and longitude.
CAltitude is the height above mean sea level at the given latitude and longitude.
DAltitude is the distance from the center of the Earth to the GPS receiver.
Attempts:
2 left
💡 Hint

Altitude usually references a standard baseline related to sea level.

🔧 Debug
advanced
1:30remaining
Identify the error in GPS coordinate validation

What error will this code raise when validating GPS latitude and longitude values?

Drone Programming
def validate_gps(lat, lon):
    if not (-90 <= lat <= 90):
        raise ValueError("Latitude out of range")
    if not (-180 <= lon <= 180):
        raise ValueError("Longitude out of range")

validate_gps(95, 45)
AValueError: Latitude out of range
BValueError: Longitude out of range
CNo error, function returns None
DTypeError: unsupported operand type(s) for <=: 'str' and 'int'
Attempts:
2 left
💡 Hint

Check the latitude value passed to the function.

📝 Syntax
advanced
1:30remaining
Find the syntax error in GPS coordinate unpacking

Which option contains a syntax error when unpacking GPS coordinates from a tuple?

Drone Programming
gps_point = (40.7128, -74.0060, 10.0)
Alat, lon, alt = gps_point
Blat, lon = gps_point[:2]
Clat, lon, alt = gps_point[0], gps_point[1]
Dlat, lon, alt = *gps_point
Attempts:
2 left
💡 Hint

Check the use of the unpacking operator (*) in assignment.

🚀 Application
expert
2:30remaining
Calculate new GPS coordinate after moving north by 1 km

Given a GPS coordinate (latitude, longitude, altitude), which option correctly calculates the new latitude after moving exactly 1 km north, assuming Earth radius 6371 km?

Drone Programming
from math import radians, degrees

def move_north(lat, lon, alt, km):
    R = 6371  # Earth radius in km
    new_lat = lat + degrees(km / R)
    return (new_lat, lon, alt)

start = (0, 0, 0)
result = move_north(*start, 1)
print(tuple(round(x, 6) if isinstance(x, float) else x for x in result))
A(0.008993, 0, 0)
B(0.009, 0, 0)
C(0.0009, 0, 0)
D(0.08993, 0, 0)
Attempts:
2 left
💡 Hint

1 degree latitude is approximately 111 km. Use degrees(km / R) to convert km to degrees.