parse

Function parse 

Source
pub fn parse(input: &str) -> Result<Coordinate, Error>
Expand description

Parse coordinates from a variety of string formats.

Parses coordinates in DMS (Degrees Minutes Seconds) format with different separators and hemisphere indicators. Also handles decimal degree formats.

§Examples

use loose_dms::parse;

// Parse DMS coordinates with hemisphere at end
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 DMS coordinates with hemisphere at start
let coord = parse("N59°12'7.7\" W02°15'39.6\"").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);

§Errors

Returns Error::CouldNotParse if the string cannot be parsed as valid coordinates. This includes if:

  • The string format is invalid
  • Values are out of valid ranges (degrees: 0-180, minutes/seconds: 0-60)
  • Required parts are missing