pub struct Location {
pub latitude: f64,
pub longitude: f64,
}
Expand description
A location represented with a latitude and longitude
Fields§
§latitude: f64
§longitude: f64
Implementations§
Source§impl Location
impl Location
Sourcepub fn new(latitude: f64, longitude: f64) -> Self
pub fn new(latitude: f64, longitude: f64) -> Self
Creates a new location
Examples found in repository?
examples/basic.rs (line 4)
3fn main() {
4 let start = Location::new(38.898556, -77.037852);
5 let end = Location::new(38.897147, -77.043934);
6
7 let km = start.distance_to(&end, Unit::Kilometer);
8 let miles = start.distance_to(&end, Unit::Mile);
9 let custom = start.distance_to(&end, Unit::CustomSphere(50.0));
10
11 println!("Distance: {} km", &km);
12 println!("Distance: {} miles", &miles);
13 println!("Distance on a custom sphere with a radius of 50 cm: {} cm", &custom);
14}
Sourcepub fn distance_to(&self, other: &Location, unit: Unit) -> f64
pub fn distance_to(&self, other: &Location, unit: Unit) -> f64
Calculates the distance between two locations and returns the distance in the assigned unit
use haversine_redux::{Location, Unit};
fn main() {
let start = Location::new(38.898556, -77.037852);
let end = Location::new(38.897147, -77.043934);
let km = start.distance_to(&end, Unit::Kilometer);
let miles = start.distance_to(&end, Unit::Mile);
}
Examples found in repository?
examples/basic.rs (line 7)
3fn main() {
4 let start = Location::new(38.898556, -77.037852);
5 let end = Location::new(38.897147, -77.043934);
6
7 let km = start.distance_to(&end, Unit::Kilometer);
8 let miles = start.distance_to(&end, Unit::Mile);
9 let custom = start.distance_to(&end, Unit::CustomSphere(50.0));
10
11 println!("Distance: {} km", &km);
12 println!("Distance: {} miles", &miles);
13 println!("Distance on a custom sphere with a radius of 50 cm: {} cm", &custom);
14}
Sourcepub fn miles_to(&self, other: &Location) -> f64
pub fn miles_to(&self, other: &Location) -> f64
Helper function, equivalent of
ⓘ
start.distance_to(&end, Unit::Mile);
Sourcepub fn kilometers_to(&self, other: &Location) -> f64
pub fn kilometers_to(&self, other: &Location) -> f64
Helper function, equivalent of
ⓘ
start.distance_to(&end, Unit::Kilometer);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Location
impl RefUnwindSafe for Location
impl Send for Location
impl Sync for Location
impl Unpin for Location
impl UnwindSafe for Location
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more