distance_gem 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/distance_gem.rb +32 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5b3201ad19663c023ff2f6f642b7e1bd99c9aa7cd89a05ca3b474baa52a15729
|
|
4
|
+
data.tar.gz: acb5fbadd2f3c415ccab2a0e24fc1fa5e30325e99d169978d3ee38af9be9ac22
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 871ad7bf7e1f6866d9055fb64734f57ca99df81f47647544aff38503cbaabf3868551fbbed1ead26943416271f397a4be9cf6fb3272eaa92c1c1db49ca72ecf8
|
|
7
|
+
data.tar.gz: e6be59854105c9f710a3b2931008c3fcefc8bad3d575069c7a6231a7a02afc10908d384a0598ecdaa783a1845259d6bd0e2f9a414e3b6225a9a751bc7d43ffb3
|
data/lib/distance_gem.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Distance
|
|
2
|
+
|
|
3
|
+
# Find the distance between two latitude,longitude objects
|
|
4
|
+
#
|
|
5
|
+
# @param {latitude:Float,longitude:Float},{latitude:Float,longitude:Float}
|
|
6
|
+
# @return Float
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# Coordinate = Struct.new(:latitude, :longitude)
|
|
10
|
+
# from_location = Coordinate.new(37.519608, -121.92349)
|
|
11
|
+
# to_location = Coordinate.new(37.519677, -121.923814)
|
|
12
|
+
# distance_between(from_location,to_location) #=> 0.18
|
|
13
|
+
|
|
14
|
+
def distance_between(from, to)
|
|
15
|
+
loc1 = [from.latitude,from.longitude]
|
|
16
|
+
loc2 = [to.latitude,to.longitude]
|
|
17
|
+
rad_per_deg = Math::PI/180 # PI / 180
|
|
18
|
+
rkm = 6371 # Earth radius in kilometers
|
|
19
|
+
rm = rkm * 1000 # Radius in meters
|
|
20
|
+
|
|
21
|
+
dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
|
|
22
|
+
dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg
|
|
23
|
+
|
|
24
|
+
lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg }
|
|
25
|
+
lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg }
|
|
26
|
+
|
|
27
|
+
a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
|
|
28
|
+
c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
|
|
29
|
+
|
|
30
|
+
(rm * c)/1609.344 # Delta in miles
|
|
31
|
+
end
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: distance_gem
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Meenakshi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-05-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/distance_gem.rb
|
|
20
|
+
homepage: https://github.com/Meenakshi-Anand/Distance-Ruby-Gem
|
|
21
|
+
licenses: []
|
|
22
|
+
metadata: {}
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0'
|
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
requirements: []
|
|
38
|
+
rubyforge_project:
|
|
39
|
+
rubygems_version: 2.7.6
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Calculates the distance in miles between two latitude,longitude objects
|
|
43
|
+
test_files: []
|