pub struct Coordinate { /* private fields */ }Expand description
A geographic coordinate expressed as a (latitude, longitude) pair.
§Examples
use lat_long::{Angle, Coordinate, Latitude, Longitude};
let lat = Latitude::new(51, 30, 26.0).unwrap();
let lon = Longitude::new(0, 7, 39.0).unwrap();
let london = Coordinate::new(lat, lon);
println!("{london}"); // decimal degrees
println!("{london:#}"); // degrees–minutes–secondsImplementations§
Source§impl Coordinate
impl Coordinate
Sourcepub const fn new(lat: Latitude, long: Longitude) -> Self
pub const fn new(lat: Latitude, long: Longitude) -> Self
Construct a new Coordinate from a validated Latitude and Longitude.
§Examples
use lat_long::{Angle, Coordinate, Latitude, Longitude};
let lat = Latitude::new(48, 51, 30.0).unwrap();
let lon = Longitude::new(2, 21, 8.0).unwrap();
let paris = Coordinate::new(lat, lon);
assert!(paris.is_northern());
assert!(paris.is_eastern());Sourcepub const fn with_latitude(self, lat: Latitude) -> Self
pub const fn with_latitude(self, lat: Latitude) -> Self
Return a new Coordinate with the latitude component replaced.
Sourcepub const fn with_longitude(self, long: Longitude) -> Self
pub const fn with_longitude(self, long: Longitude) -> Self
Return a new Coordinate with the longitude component replaced.
Sourcepub fn is_on_equator(&self) -> bool
pub fn is_on_equator(&self) -> bool
Returns true if this coordinate lies on the equator.
Sourcepub fn is_northern(&self) -> bool
pub fn is_northern(&self) -> bool
Returns true if this coordinate is in the northern hemisphere.
Sourcepub fn is_southern(&self) -> bool
pub fn is_southern(&self) -> bool
Returns true if this coordinate is in the southern hemisphere.
Sourcepub fn is_on_international_reference_meridian(&self) -> bool
pub fn is_on_international_reference_meridian(&self) -> bool
Returns true if this coordinate lies on the international reference meridian.
Sourcepub fn is_western(&self) -> bool
pub fn is_western(&self) -> bool
Returns true if this coordinate is in the western hemisphere.
Sourcepub fn is_eastern(&self) -> bool
pub fn is_eastern(&self) -> bool
Returns true if this coordinate is in the eastern hemisphere.
Sourcepub fn to_url_string(&self) -> String
pub fn to_url_string(&self) -> String
Format this coordinate as a geo: URI string.
The format is geo:<lat>,<lon> using decimal degrees with 8 places of
precision, as per RFC 5870.
§Examples
use lat_long::{Angle, Coordinate, Latitude, Longitude};
let lat = Latitude::new(48, 51, 30.0).unwrap();
let lon = Longitude::new(2, 21, 8.0).unwrap();
let paris = Coordinate::new(lat, lon);
assert!(paris.to_url_string().starts_with("geo:"));Sourcepub fn to_microformat_string(&self) -> String
pub fn to_microformat_string(&self) -> String
Format this coordinate as a microformat string.
This follows the microformat standard for representing coordinates specified in mf-geo and referenced by hCard and hCalendar.
§Examples
use lat_long::{Angle, Coordinate, Latitude, Longitude};
let lat = Latitude::new(48, 51, 30.0).unwrap();
let lon = Longitude::new(2, 21, 8.0).unwrap();
let paris = Coordinate::new(lat, lon);
assert!(paris.to_microformat_string().contains("class=\"latitude\""));
assert!(paris.to_microformat_string().contains("class=\"longitude\""));Trait Implementations§
Source§impl Clone for Coordinate
impl Clone for Coordinate
Source§fn clone(&self) -> Coordinate
fn clone(&self) -> Coordinate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Coordinate
impl Debug for Coordinate
Source§impl Default for Coordinate
impl Default for Coordinate
Source§impl<'de> Deserialize<'de> for Coordinate
impl<'de> Deserialize<'de> for Coordinate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for Coordinate
impl Display for Coordinate
Source§impl Formatter for Coordinate
impl Formatter for Coordinate
fn format<W: Write>(&self, f: &mut W, fmt: &FormatOptions) -> Result
fn to_formatted_string(&self, fmt: &FormatOptions) -> String
Source§impl From<Coordinate> for (Latitude, Longitude)
impl From<Coordinate> for (Latitude, Longitude)
Source§fn from(value: Coordinate) -> Self
fn from(value: Coordinate) -> Self
Source§impl From<Coordinate> for Url
Available on crate feature urn only.
impl From<Coordinate> for Url
urn only.Source§fn from(coord: Coordinate) -> Self
fn from(coord: Coordinate) -> Self
Source§impl From<Latitude> for Coordinate
impl From<Latitude> for Coordinate
Source§impl From<Longitude> for Coordinate
impl From<Longitude> for Coordinate
Source§impl FromStr for Coordinate
impl FromStr for Coordinate
Source§impl Hash for Coordinate
impl Hash for Coordinate
Source§impl PartialEq for Coordinate
impl PartialEq for Coordinate
Source§impl Serialize for Coordinate
impl Serialize for Coordinate
Source§impl TryFrom<Url> for Coordinate
Available on crate feature urn only.
impl TryFrom<Url> for Coordinate
urn only.