Skip to content

Instantly share code, notes, and snippets.

@MartinThoma
Created March 3, 2021 19:33
Show Gist options
  • Save MartinThoma/ba37dfc6f8a88ddd7dc4e107b4755526 to your computer and use it in GitHub Desktop.
Save MartinThoma/ba37dfc6f8a88ddd7dc4e107b4755526 to your computer and use it in GitHub Desktop.
from typing import Optional
class Position:
MIN_LATITUDE = -90
MAX_LATITUDE = 90
MIN_LONGITUDE = -180
MAX_LONGITUDE = 180
def __init__(
self, longitude: float, latitude: float, address: Optional[str] = None
):
self.longitude = longitude
self.latitude = latitude
self.address = address
@property
def latitude(self) -> float:
"""Getter for latitude."""
return self._latitude
@latitude.setter
def latitude(self, latitude: float) -> None:
"""Setter for latitude."""
if not (Position.MIN_LATITUDE <= latitude <= Position.MAX_LATITUDE):
raise ValueError(f"latitude was {latitude}, but has to be in [-90, 90]")
self._latitude = latitude
@property
def longitude(self) -> float:
"""Getter for longitude."""
return self._longitude
@longitude.setter
def longitude(self, longitude: float) -> None:
"""Setter for longitude."""
if not (Position.MIN_LONGITUDE <= longitude <= Position.MAX_LONGITUDE):
raise ValueError(f"longitude was {longitude}, but has to be in [-180, 180]")
self._longitude = longitude
pos1 = Position(49.0127913, 8.4231381, "Parkstraße 17")
pos2 = Position(42.1238762, 9.1649964)
def get_distance(p1: Position, p2: Position) -> float:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment