#NEWLINE# def haversine( point1 , point2 , **kwargs ) : #NEWLINE# #INDENT# ' Calculate the great-circle distance bewteen two points on the Earth surface.\n\n    :input: two 2-tuples, containing the latitude and longitude of each point\n    in decimal degrees.\n\n    Example: haversine((45.7597, 4.8422), (48.8567, 2.3508))\n\n    :output: Returns the distance bewteen the two points.\n    The default unit is kilometers. Miles can be returned\n    if the ``miles`` parameter is set to True.\n\n    ' #NEWLINE# lookup_units = { #NEWLINE# #INDENT# 'miles' : 'miles' , #NEWLINE# 'mile' : 'miles' , #NEWLINE# 'mi' : 'miles' , #NEWLINE# 'ml' : 'miles' , #NEWLINE# 'kilometers' : 'kilometers' , #NEWLINE# 'kilometres' : 'kilometers' , #NEWLINE# 'kilometer' : 'kilometers' , #NEWLINE# 'kilometre' : 'kilometers' , #NEWLINE# 'km' : 'kilometers' , #NEWLINE# 'meters' : 'meters' , #NEWLINE# 'metres' : 'meters' , #NEWLINE# 'meter' : 'meters' , #NEWLINE# 'metre' : 'meters' , #NEWLINE# 'm' : 'meters' , #NEWLINE# 'feet' : 'feet' , #NEWLINE# 'f' : 'feet' , #NEWLINE# 'ft' : 'feet' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( point1 . ok and point2 . ok ) : #NEWLINE# #INDENT# ( lat1 , lng1 , lat2 , lng2 ) = list ( map ( radians , ( point1 . latlng + point2 . latlng ) ) ) #NEWLINE# lat = ( lat2 - lat1 ) #NEWLINE# lng = ( lng2 - lng1 ) #NEWLINE# d = ( ( sin ( ( lat / 2 ) ) ** 2 ) + ( ( cos ( lat1 ) * cos ( lat2 ) ) * ( sin ( ( lng / 2 ) ) ** 2 ) ) ) #NEWLINE# h = ( ( 2 * AVG_EARTH_RADIUS ) * asin ( sqrt ( d ) ) ) #NEWLINE# units = kwargs . get ( 'units' , 'kilometers' ) . lower ( ) #NEWLINE# units_calculation = { #NEWLINE# #INDENT# 'miles' : ( h * 0.621371 ) , #NEWLINE# 'feet' : ( ( h * 0.621371 ) * 5280 ) , #NEWLINE# 'meters' : ( h * 1000 ) , #NEWLINE# 'kilometers' : h , #NEWLINE# #UNINDENT# } #NEWLINE# if ( units in lookup_units ) : #NEWLINE# #INDENT# return units_calculation [ lookup_units [ units ] ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Unknown units of measurement' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# print ( '[WARNING] Error calculating the following two locations.\nPoints: {0} to {1}' . format ( point1 . location , point2 . location ) )