from typing import Union


def longitude(value: Union[str, float]) -> float:
    """Validate longitude."""
    float_value = float(value)
    if -180 <= float_value <= 180:
        return float_value
    raise ValueError("longitude must be between -180 and 180")