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?
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))
Remember the Haversine formula calculates great-circle distance between two points on a sphere.
The code uses the Haversine formula correctly and calculates the distance between Warsaw (52.2296756, 21.0122287) and Rome (41.8919300, 12.5113300) as approximately 1317.5 km.
Which statement correctly describes the altitude value in a GPS coordinate system?
Altitude usually references a standard baseline related to sea level.
Altitude in GPS coordinates is typically measured as height above mean sea level, not just the Earth's surface or center.
What error will this code raise when validating GPS latitude and longitude values?
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)
Check the latitude value passed to the function.
The latitude 95 is outside the valid range -90 to 90, so the function raises a ValueError with message 'Latitude out of range'.
Which option contains a syntax error when unpacking GPS coordinates from a tuple?
gps_point = (40.7128, -74.0060, 10.0)
Check the use of the unpacking operator (*) in assignment.
Option D uses '*gps_point' incorrectly in assignment, which causes a syntax error. The unpacking operator * cannot be used on the right side like this in an assignment.
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?
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))
1 degree latitude is approximately 111 km. Use degrees(km / R) to convert km to degrees.
The code converts 1 km to degrees latitude by dividing by Earth's radius and converting radians to degrees. The result is approximately 0.008993 degrees latitude north.