Just encountered a bug in my code where I swapped the order or lat and lon values. It is so easy to apply the wrong order and not finding it. In fact my algorithm works despite I swapped the coordinates. Only a after I notice a slight deviation from the expected result did I start an extensive investigation and identified the mistake.
Is there a standard order to express the coordinate in computing system? It seems the only way to make software reliable is to adopt a consistent order. So I looked at several software system. Here is what I find.
Lat Lon Order
- Leaflet library
- Google Maps API
- General Transit Feed Specification – lat is listed before lon in the documentation.
Lon Lat Order
- GeoJSON – The order of elements must follow x, y, z order (longitude, latitude, altitude, …)
- KML – <gx:coord> A coordinate value consisting of three values for longitude, latitude, and altitude, … Also the values are explicitly tagged as XML element.
There is not a consistent order used in the field. In addition there is also variation of the 3 letter shorthand for longitude – lng v.s. lon. Sigh… No wonder I have messed up.
This is what I’m going to use – lat, lon, so as to follow the verbal convention.