latlong v0.1.0 LatLong
A parser for all the ways that a longitude or latitude may be specified. Comments and suggestions on how this might have been better written are welcome. The following lat long formats are allowed … all are equivalent:
- 38.8977, -77.0365
- 38° 53’ 51.635” N, 77° 2’ 11.507” W
- 38 53 51.635 N, 77 2 11.507 W
- N 38° 53’ 51.635”, W 77° 2’ 11.507”
- N 38 53 51.635, W 77 2 11.507
- 38 53 51.635, -77 2 11.507
And some other examples that are for different locations:
- -31.96, 115.84
- 90, 0 (North Pole)
- 41 25 01N, 120 58 57W
- 41°25’01”N, 120°58’57”W
- S17 33 08.352, W69 01 29.74
- 41 25N, 120 58W
- 41°25’N, 120°58’W
- N41 25.117, W120 58.292
- 41 N, 120 W
- 41°N, 120°W
- N41.092, W120.8362
- 90S, 0E (South Pole)
In addition, the latitude may be in one format and the longitude in another.
Parsing
The strings are parsed with a state machine checking the next part of the string, saving the various parts in a map. Each pass of the state machine provides the next Float if available and the next grapheme. The state machine lets the call fall to the appropriate state handler and then the next part is examined until there isn’t anything left in the string.
Summary
Functions
Parses string representations of a latitude and longitude into decimals. The latitude and longitude must be provided as single string argument with a separating comma
Parses string representations of a latitude and longitude into decimals. The latitude and longitude must be provided as string arguments
Types
Functions
Parses string representations of a latitude and longitude into decimals. The latitude and longitude must be provided as single string argument with a separating comma.