Bird
Raised Fist0
Drone Programmingprogramming~20 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. What does the altitude value represent in a drone's GPS coordinate system?
easy
A. The height of the drone above sea level
B. The distance east or west from the Prime Meridian
C. The distance north or south from the Equator
D. The speed of the drone in meters per second

Solution

  1. Step 1: Understand GPS coordinate components

    GPS coordinates include latitude, longitude, and altitude. Latitude and longitude locate position on Earth, altitude shows height.
  2. Step 2: Identify altitude meaning

    Altitude measures how high the drone is above sea level, not horizontal position or speed.
  3. Final Answer:

    The height of the drone above sea level -> Option A
  4. Quick Check:

    Altitude = height above sea level [OK]
Hint: Altitude means height, not horizontal position [OK]
Common Mistakes:
  • Confusing altitude with latitude or longitude
  • Thinking altitude measures speed
  • Mixing altitude with horizontal distance
2. Which of the following is the correct way to represent a GPS coordinate in code for a drone?
easy
A. gps = {latitude: altitude, longitude: altitude}
B. gps = [altitude, longitude, latitude]
C. gps = (latitude, longitude, altitude)
D. gps = latitude + longitude + altitude

Solution

  1. Step 1: Recognize GPS coordinate format

    GPS coordinates are usually stored as a tuple or list with latitude, longitude, and altitude in order.
  2. Step 2: Check each option

    gps = (latitude, longitude, altitude) uses a tuple with correct order. gps = [altitude, longitude, latitude] swaps order. gps = {latitude: altitude, longitude: altitude} uses a dictionary incorrectly. gps = latitude + longitude + altitude adds numbers incorrectly.
  3. Final Answer:

    gps = (latitude, longitude, altitude) -> Option C
  4. Quick Check:

    Tuple with lat, long, alt in order [OK]
Hint: Use (latitude, longitude, altitude) tuple for GPS [OK]
Common Mistakes:
  • Mixing order of latitude and longitude
  • Using addition instead of grouping
  • Using dictionary with wrong keys
3. Given the code snippet:
gps = (34.05, -118.25, 100)
latitude, longitude, altitude = gps
print(f"Lat: {latitude}, Long: {longitude}, Alt: {altitude}m")

What will be the output?
medium
A. Lat: 100, Long: 34.05, Alt: -118.25m
B. Lat: 34.05, Long: -118.25, Alt: 100m
C. Lat: -118.25, Long: 34.05, Alt: 100m
D. SyntaxError

Solution

  1. Step 1: Unpack the GPS tuple

    The tuple gps = (34.05, -118.25, 100) assigns latitude=34.05, longitude=-118.25, altitude=100.
  2. Step 2: Print formatted string

    The print statement outputs the values with labels and 'm' for meters.
  3. Final Answer:

    Lat: 34.05, Long: -118.25, Alt: 100m -> Option B
  4. Quick Check:

    Unpack tuple correctly and print [OK]
Hint: Unpack tuple in order: latitude, longitude, altitude [OK]
Common Mistakes:
  • Swapping latitude and longitude values
  • Confusing altitude with latitude
  • Syntax errors from wrong unpacking
4. Identify the error in this code snippet for setting a drone's GPS position:
gps = (latitude, longitude, altitude)
latitude = 40.7128
longitude = -74.0060
altitude = 50
print(gps)
medium
A. gps tuple is assigned before variables, so it holds old values
B. Latitude and longitude values are swapped
C. Altitude should be a string, not a number
D. print(gps) causes a syntax error

Solution

  1. Step 1: Analyze variable assignment order

    gps is assigned before latitude, longitude, altitude variables get values, so gps holds undefined or old values.
  2. Step 2: Understand variable update effect

    Changing latitude, longitude, altitude after gps assignment does not update gps tuple automatically.
  3. Final Answer:

    gps tuple is assigned before variables, so it holds old values -> Option A
  4. Quick Check:

    Assign variables before tuple [OK]
Hint: Assign variables before creating gps tuple [OK]
Common Mistakes:
  • Assigning tuple before variables
  • Swapping latitude and longitude values
  • Thinking print causes error
5. You want to write a function is_above_altitude(gps, threshold) that returns True if the drone's altitude is above a given threshold. Which code correctly implements this?
hard
A. def is_above_altitude(gps, threshold): return gps[2] < threshold
B. def is_above_altitude(gps, threshold): return gps[0] > threshold
C. def is_above_altitude(gps, threshold): return gps[1] > threshold
D. def is_above_altitude(gps, threshold): return gps[2] > threshold

Solution

  1. Step 1: Identify altitude index in GPS tuple

    GPS tuple is (latitude, longitude, altitude), so altitude is at index 2.
  2. Step 2: Compare altitude with threshold

    Return True if gps[2] (altitude) is greater than threshold.
  3. Final Answer:

    def is_above_altitude(gps, threshold): return gps[2] > threshold -> Option D
  4. Quick Check:

    Check altitude at index 2 > threshold [OK]
Hint: Altitude is gps[2], compare with threshold [OK]
Common Mistakes:
  • Using wrong index for altitude
  • Using less than instead of greater than
  • Confusing latitude or longitude with altitude