A Rust crate for parsing geographical coordinates from strings in various formats, including Degrees Minutes Seconds (DMS) and decimal degrees. This crate is designed to be flexible with input formats while ensuring parsed values are valid geographical coordinates.
This is a direct port of the parse-dms JavaScript library by gmaclennan.
- Parse DMS strings with degrees, minutes, and seconds
- Support for hemisphere indicators (N, E, S, W) in different positions
- Handle decimal degrees format
- Flexible separator handling
- Returns structured coordinates with latitude and longitude
Add this to your Cargo.toml:
[dependencies]
loose-dms = "0.1.2"use loose_dms::parse;
fn main() {
// Parse DMS format
let coord = parse("59°12'7.7\"N 02°15'39.6\"W").unwrap();
assert_eq!(coord.lat, 59.20213888888889);
assert_eq!(coord.lng, -2.261);
// Parse decimal degrees
let coord = parse("51.5, -0.126").unwrap();
assert_eq!(coord.lat, 51.5);
assert_eq!(coord.lng, -0.126);
}This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to gmaclennan for the original JavaScript implementation.