| Crates.io | loose-dms |
| lib.rs | loose-dms |
| version | 0.1.1 |
| created_at | 2024-12-18 01:30:30.816644+00 |
| updated_at | 2024-12-18 01:34:21.91715+00 |
| description | Parse geographical coordinates from strings in DMS or decimal format |
| homepage | |
| repository | https://github.com/carterharrison/loose-dms |
| max_upload_size | |
| id | 1487012 |
| size | 15,918 |
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.
Add this to your Cargo.toml:
[dependencies]
loose-dms = "0.1.0"
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.