lib/parse/model/geopoint.rb
def distance_in_km(geopoint,lng = nil)
      unless geopoint.is_a?(Parse::GeoPoint)
        geopoint = Parse::GeoPoint.new(geopoint, lng)
      end

      dtor = Math::PI/180
      r = 6378.14
      r_lat1 = self.latitude * dtor
      r_lng1 = self.longitude * dtor
      r_lat2 = geopoint.latitude * dtor
      r_lng2 = geopoint.longitude * dtor

      delta_lat = r_lat1 - r_lat2
      delta_lng = r_lng1 - r_lng2

      a = (Math::sin(delta_lat/2.0) ** 2).to_f + (Math::cos(r_lat1) * Math::cos(r_lat2) * ( Math::sin(delta_lng/2.0) ** 2 ) )
      c = 2.0 * Math::atan2(Math::sqrt(a), Math::sqrt(1.0-a))
      d = r * c
      d
    end
def distance_in_km(geopoint,lng = nil)
      unless geopoint.is_a?(Parse::GeoPoint)
        geopoint = Parse::GeoPoint.new(geopoint, lng)
      end

      dtor = Math::PI/180
      r = 6378.14
      r_lat1 = self.latitude * dtor
      r_lng1 = self.longitude * dtor
      r_lat2 = geopoint.latitude * dtor
      r_lng2 = geopoint.longitude * dtor

      delta_lat = r_lat1 - r_lat2
      delta_lng = r_lng1 - r_lng2

      a = (Math::sin(delta_lat/2.0) ** 2).to_f + (Math::cos(r_lat1) * Math::cos(r_lat2) * ( Math::sin(delta_lng/2.0) ** 2 ) )
      c = 2.0 * Math::atan2(Math::sqrt(a), Math::sqrt(1.0-a))
      d = r * c
      d
    end
def distance_in_km ( geopoint , lng = nil ) unless geopoint . is_a? ( Parse :: GeoPoint ) geopoint = Parse :: GeoPoint . new ( geopoint , lng ) end dtor = Math :: PI / 180 r = 6378.14 r_lat1 = self . latitude * dtor r_lng1 = self . longitude * dtor r_lat2 = geopoint . latitude * dtor r_lng2 = geopoint . longitude * dtor delta_lat = r_lat1 - r_lat2 delta_lng = r_lng1 - r_lng2 a = ( Math :: sin ( delta_lat / 2.0 ) ** 2 ) . to_f + ( Math :: cos ( r_lat1 ) * Math :: cos ( r_lat2 ) * ( Math :: sin ( delta_lng / 2.0 ) ** 2 ) ) c = 2.0 * Math :: atan2 ( Math :: sqrt ( a ) , Math :: sqrt ( 1.0 - a ) ) d = r * c d end
Calculate the distance in kilometers to another GeoPoint using Haversine
 method. You may also call this method with a latitude and longitude.
 @example
   point.distance_in_km(geotpoint)
   point.distance_in_km(lat, lng)

 @param geopoint [GeoPoint]
 @param lng [Float] Longitude assuming that the first parameter is a latitude instead of a GeoPoint.
 @return [Float] number of miles between geopoints.
 @see #distance_in_miles
Calculate the distance in kilometers to another GeoPoint using Haversine method . You may also call this method with a latitude and longitude . @example point . distance_in_km ( geotpoint ) point . distance_in_km ( lat lng )