geoproximity-monster 1.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.
Files changed (3) hide show
  1. checksums.yaml +15 -0
  2. data/lib/geo_proximity_monster.rb +46 -0
  3. metadata +44 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGJhZjFjZTI5ODk0MDViNGJlNTAxMzAwNTBiNzNiOTljM2YwODZjMg==
5
+ data.tar.gz: !binary |-
6
+ MTMwNDI4ODNhMDRiZjFjOTYwZjJkOThmOTcwNWU4ZTBjODg3NjI0Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmMxZjZmMjQ0YTkxMjE1MmVkMGUyYmUyMzE0YWFmY2M1ZTc1MzY5YWIzOTBh
10
+ NTMzOTc1Y2ZiZjFmNTFkNzE1MTA3MjBlZmI5OTM0ODIzN2U4OGE4MWJiZDg3
11
+ ODljZjdmN2U0ZDhmOGQ5NzI0MWE1MjM0OTY0ZjVhZWRmMjRjNDQ=
12
+ data.tar.gz: !binary |-
13
+ MjEyOTZmNDhiYjI3YzBjMTIwMGFlZmVmZDg0YzVhM2Q0NmVmZTY4ZmIxYTA5
14
+ OWJhM2UzMzdhODIyZDkzNjQ1NjU5ODNjNzgzNjZkMGM2ZjA5ODg3MmQ3MmU1
15
+ ZjM3OGE4MWFmZjFiOTljYmNhZWQyYTY3M2MyMmM5YmY1OTUxOGU=
@@ -0,0 +1,46 @@
1
+ class GeoProximityMonster
2
+ attr_reader :loc_1_lat, :loc_1_long
3
+
4
+ def initialize( lat1 , long1 )
5
+ @loc_1_lat = lat1
6
+ @loc_1_long = long1
7
+ end
8
+
9
+ def get_distance_to( lat2 , long2 , options = {:unit => :meters})
10
+ a = [loc_1_lat.to_f , loc_1_long.to_f]
11
+ b = [lat2.to_f , long2.to_f]
12
+ rad_per_deg = Math::PI/180 # PI / 180
13
+ rkm = 6371 # Earth radius in kilometers
14
+ rm = rkm * 1000 # Radius in meters
15
+ dlon_rad = (b[1].to_f-a[1].to_f) * rad_per_deg # Delta, converted to rad
16
+ dlat_rad = (b[0].to_f-a[0].to_f) * rad_per_deg
17
+ lat1_rad, lon1_rad = a.map! {|i| i * rad_per_deg }
18
+ lat2_rad, lon2_rad = b.map! {|i| i * rad_per_deg }
19
+ a = Math.sin(dlat_rad/2)**2 + Math.cos(lat1_rad) * Math.cos(lat2_rad) * Math.sin(dlon_rad/2)**2
20
+ c = 2 * Math.asin(Math.sqrt(a))
21
+ return rm * c if options[:unit] == :meters # Delta in meters
22
+ return ((rm * c).to_f)*(0.000621371) if options[:unit] == :miles # Delta in miles
23
+ end
24
+
25
+ def get_closet_from_pool( pool = [])
26
+ pool_locations = pool
27
+ closest_loc = nil
28
+ smallest_distance = nil
29
+ unless pool_locations.empty?
30
+ pool_locations.each do |this_loc|
31
+ this_distance = get_distance_to( this_loc[:latitude] , this_loc[:longitude] )
32
+ if smallest_distance.nil?
33
+ smallest_distance = this_distance
34
+ closest_loc = this_loc
35
+ else
36
+ if this_distance.abs < smallest_distance.abs
37
+ smallest_distance = this_distance
38
+ closest_loc = this_loc
39
+ end
40
+ end
41
+ end
42
+ end
43
+ return closest_loc
44
+ end
45
+
46
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geoproximity-monster
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aghyad Saleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: geo proximity calculator gem
14
+ email: contact@aghyadsaleh.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/geo_proximity_monster.rb
20
+ homepage: https://github.com/aghyad/geoproximity-monster
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: geo proximity calculator gem
44
+ test_files: []