Sha256: 2358a71fd501f2c4d2a1b1fde11305d5c0cf03c9a116362a6b79f5bb22badb2e

Contents?: true

Size: 967 Bytes

Versions: 1

Compression:

Stored size: 967 Bytes

Contents

# denver = CLLocationCoordinate2D.new(39.764032,-104.963112)
# cincinnati = CLLocationCoordinate2D.new(39.267024,-84.251736)
# denver.distance_to(cincinnati).miles
# denver.delta_miles()
class CLLocationCoordinate2D

  def delta_miles(dx, dy)
    earth_radius = 3960.0

    radius_at_latitude = earth_radius * Math.cos(self.latitude * Math::PI / 180.0)
    if radius_at_latitude > 0
      delta_lng = dx / radius_at_latitude
      delta_lng *= 180.0 / Math::PI
    else
      delta_lng = 0
    end

    delta_lat = dy / earth_radius
    delta_lat *= 180.0 / Math::PI
    CLLocationCoordinate2D.new(self.latitude + delta_lat, self.longitude + delta_lng)
  end

  def distance_to(cl_location_2d)
    my_location = CLLocation.alloc.initWithLatitude(self.latitude, longitude:self.longitude)
    other_location = CLLocation.alloc.initWithLatitude(cl_location_2d.latitude, longitude:cl_location_2d.longitude)
    my_location.distanceFromLocation(other_location)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sugarcube-0.11.1 lib/sugarcube/core_location.rb