#![warn(missing_docs)]
#[derive(Debug, Clone)]
pub struct Place {
pub city: String,
pub region: String,
pub region_code: String,
pub district: String,
pub country_code: String,
pub country_name: String,
pub postal_code: String,
pub timezone: String,
pub timezone_abbr: String,
pub utc_offset: i32,
pub utc_offset_str: String,
pub latitude: f64,
pub longitude: f64,
pub currency: String,
pub continent_code: String,
pub continent_name: String,
pub is_eu: bool,
pub dst_active: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct Location {
pub latitude: f64,
pub longitude: f64,
}
impl Location {
pub fn new(latitude: f64, longitude: f64) -> Self {
Self {
latitude,
longitude,
}
}
pub fn distance_to(&self, other: &Location) -> f64 {
let lat1 = self.latitude.to_radians();
let lat2 = other.latitude.to_radians();
let delta_lat = (other.latitude - self.latitude).to_radians();
let delta_lon = (other.longitude - self.longitude).to_radians();
let a = (delta_lat / 2.0).sin().powi(2)
+ lat1.cos() * lat2.cos() * (delta_lon / 2.0).sin().powi(2);
6371.0 * 2.0 * a.sqrt().atan2((1.0 - a).sqrt())
}
}