Validate a coordinate longitude
This application sanitizes, validates and (optionally) normalizes a given decimal longitude. A longitude, specifies the east-west position of a point on Earth's surface. Longitudes are used in many operations in KML Workbench, thus the need for functions that sanitize, validate and normalize user input. Similar to Bearing and Latitude, the Longitude::isValid() function first calls KMLWB::sanitizeGeo() for security. I provide the option to call Longitude::normalize() which converts the given input to a floating point decimal between -180 and 180. (See more on normalization below)
Normalization of a longitude is simply the process of converting a value that lies outside of the "normal" range of Earth longitudes (-180° to 180°) to one that is. It is not always appropriate to apply this option, as there are many instances in which "non-normal" longitudes are required to perform calculations accurately, and to display elements on digital maps as desired.
Rendering behavior varies on different applications but, when displaying
an element that crosses the antimeridian (180°/-180°), the
longitudes typically must increment to values above 180 or below -180. For
example, a line from Petropavlovsk, Kamchatka (53.01°,158.64°)
to Kodiak, Alaska (57.79°,-152.41°) is correctly described
by the KML coordinates:
Note that the longitude for Kodiak is not 158.64°, but 207.59°, indicating that the path continues eastward 27.59 degrees beyond 180° (180 + 27.59 = 207.59). In many mapping applications, using the normal longitude can result in a line being drawn westward around the globe instead.
Google Earth defaults to drawing the shorter path between two points, regardless of normalization. When drawing a path on Google Earth that is longer than half the circumference of Earth, a third midpoint coordinate must be added. Conversely, OpenLayers, the mapping application used here on KML Workbench pages, renders non-normal longitudes accurately.
All calculations of distance on KML Workbench are performed using non-normalized longitudes.
Longitudes are normalized with the formula: ((longitude + 180) mod 360) -180