def __sub__(self, other):
"""Subtraction.
Args:
other: the LatLng which this LatLng is subtracted by.
Returns:
the great circle distance between two LatLng objects as computed
by the Haversine formula.
"""
assert isinstance(other, LatLng)
lat_rad = math.radians(self._lat)
lng_rad = math.radians(self._lng)
other_lat_rad = math.radians(other.latitude)
other_lng_rad = math.radians(other.longitude)
dlat = lat_rad - other_lat_rad
dlng = lng_rad - other_lng_rad
a1 = math.sin(dlat / 2)**2
a2 = math.cos(lat_rad) * math.cos(other_lat_rad) * math.sin(dlng / 2)**2
return 2 * self._EARTH_RADIUS_METERS * math.asin(math.sqrt(a1 + a2))
评论列表
文章目录