geo_magic 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.textile} +28 -20
- data/VERSION +1 -1
- data/geo_magic.gemspec +10 -4
- data/lib/geo_magic.rb +2 -1
- data/lib/geo_magic/geocode/config.rb +23 -0
- data/lib/geo_magic/geocode/geocoder.rb +135 -0
- data/lib/geo_magic/location.rb +6 -1
- data/lib/geo_magic/map_point.rb +32 -0
- data/lib/geo_magic/point.rb +2 -1
- data/lib/geo_magic/radius.rb +77 -19
- data/lib/geo_magic/util.rb +3 -3
- data/lib/rails/config.rb +28 -0
- data/spec/fixtures/config.yaml +2 -0
- data/spec/geo_magic/geocoder_spec.rb +22 -0
- data/spec/geo_magic/select_nearest_spec.rb +3 -3
- metadata +13 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
h1. Geo Magic
|
2
2
|
|
3
3
|
This little clever project was the result of me not being satisfied with existing Geo Location and Coding solutions out there to suit my needs.
|
4
4
|
Many of the projects did not return quality data (fx when requesting IP or location) and others were tightly bound to Active Record and SQL databases for calculations etc.
|
@@ -10,17 +10,18 @@ This little gem should get you going...
|
|
10
10
|
|
11
11
|
You can either include the complete library like this:
|
12
12
|
|
13
|
-
require 'geo_magic'
|
13
|
+
<pre>require 'geo_magic'</pre>
|
14
|
+
|
14
15
|
|
15
16
|
Or require only the functionality you need (see usage examples below)
|
16
17
|
|
17
|
-
|
18
|
+
h2. IP and location data
|
18
19
|
|
19
|
-
Uses freegeoip.net JSON API
|
20
|
+
Uses "freegeoip.net":http://freegeoip.net JSON API
|
20
21
|
|
21
22
|
RSpec 2 examples of API usage
|
22
23
|
|
23
|
-
require 'geo_magic/remote'
|
24
|
+
<pre>require 'geo_magic/remote'
|
24
25
|
|
25
26
|
it "should get the remote IP address" do
|
26
27
|
ip = GeoMagic::Remote.my_ip
|
@@ -36,16 +37,15 @@ it "should get my location" do
|
|
36
37
|
location = GeoMagic::Remote.my_location
|
37
38
|
puts location
|
38
39
|
puts "location: #{location['city']}"
|
39
|
-
end
|
40
|
-
|
40
|
+
end
|
41
|
+
</pre>
|
41
42
|
|
42
|
-
== Distance calculation
|
43
43
|
|
44
|
-
|
44
|
+
h2. Distance calculation
|
45
45
|
|
46
46
|
RSpec 2 examples of API usage
|
47
47
|
|
48
|
-
require 'geo_magic/calculate'
|
48
|
+
<pre>require 'geo_magic/calculate'
|
49
49
|
|
50
50
|
it "calculates distance using array args" do
|
51
51
|
dist = GeoMagic::Calculate.distance [@long1, @lat1], [@long2, @lat2]
|
@@ -55,9 +55,9 @@ end
|
|
55
55
|
it "calculates distance using Point args" do
|
56
56
|
from_point = GeoMagic::Point.new @long1, @lat1
|
57
57
|
to_point = GeoMagic::Point.new @long2, @lat2
|
58
|
-
|
58
|
+
|
59
59
|
puts "from: #{from_point}, to: #{to_point}"
|
60
|
-
|
60
|
+
|
61
61
|
dist = GeoMagic::Calculate.distance from_point, to_point
|
62
62
|
puts dist
|
63
63
|
end
|
@@ -65,17 +65,25 @@ end
|
|
65
65
|
it "calculates distance using Hash args (short)" do
|
66
66
|
from_point = GeoMagic::Point.new(@long1, @lat1).to_hash :short
|
67
67
|
to_point = GeoMagic::Point.new(@long2, @lat2).to_hash :short
|
68
|
-
|
68
|
+
|
69
69
|
puts "from: #{from_point}, to: #{to_point}"
|
70
|
-
|
70
|
+
|
71
71
|
dist = GeoMagic::Calculate.distance from_point, to_point
|
72
72
|
puts dist
|
73
|
-
end
|
73
|
+
end
|
74
|
+
</pre>
|
75
|
+
|
76
|
+
h2. Extra features
|
74
77
|
|
75
|
-
|
78
|
+
Lots of extra features has been added recently. For now, please check out the specs to get an idea of the features included.
|
79
|
+
Most recently I have added support to filter a list of points for those who are within a radius of another point (see _select_neares_spec.rb_).
|
80
|
+
I have also just created a Geocode adapter for _Geocode_ and _Graticule_ (see: _geocoder_spec.rb_) - This can also easily be configured for Rails.
|
81
|
+
|
82
|
+
h2. Meta magic
|
76
83
|
|
77
84
|
You can also include the functionality directly into any class like this
|
78
85
|
|
86
|
+
<pre>
|
79
87
|
class Map
|
80
88
|
include GeoMagic::Calculate
|
81
89
|
end
|
@@ -92,10 +100,10 @@ end
|
|
92
100
|
it "calculates distance using array args" do
|
93
101
|
dist = MapCalc.distance [@long1, @lat1], [@long2, @lat2]
|
94
102
|
puts dist
|
95
|
-
end
|
96
|
-
|
103
|
+
end
|
104
|
+
</pre>
|
97
105
|
|
98
|
-
|
106
|
+
h2. Contributing to geo_magic
|
99
107
|
|
100
108
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
101
109
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
@@ -105,7 +113,7 @@ end
|
|
105
113
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
106
114
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
107
115
|
|
108
|
-
|
116
|
+
h2. Copyright
|
109
117
|
|
110
118
|
Copyright (c) 2011 Kristian Mandrup. See LICENSE.txt for
|
111
119
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/geo_magic.gemspec
CHANGED
@@ -5,16 +5,16 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{geo_magic}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2011-01-
|
12
|
+
s.date = %q{2011-01-21}
|
13
13
|
s.description = %q{Get IP and location data using freegeoip.net - can also calculate of distance between map points using haversine supporting multiple distance units}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.textile"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
@@ -22,13 +22,15 @@ Gem::Specification.new do |s|
|
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
24
|
"LICENSE.txt",
|
25
|
-
"README.
|
25
|
+
"README.textile",
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"geo_magic.gemspec",
|
29
29
|
"lib/geo_magic.rb",
|
30
30
|
"lib/geo_magic/calculate.rb",
|
31
31
|
"lib/geo_magic/distance.rb",
|
32
|
+
"lib/geo_magic/geocode/config.rb",
|
33
|
+
"lib/geo_magic/geocode/geocoder.rb",
|
32
34
|
"lib/geo_magic/location.rb",
|
33
35
|
"lib/geo_magic/map_point.rb",
|
34
36
|
"lib/geo_magic/meta.rb",
|
@@ -36,7 +38,10 @@ Gem::Specification.new do |s|
|
|
36
38
|
"lib/geo_magic/radius.rb",
|
37
39
|
"lib/geo_magic/remote.rb",
|
38
40
|
"lib/geo_magic/util.rb",
|
41
|
+
"lib/rails/config.rb",
|
42
|
+
"spec/fixtures/config.yaml",
|
39
43
|
"spec/geo_magic/calculate_spec.rb",
|
44
|
+
"spec/geo_magic/geocoder_spec.rb",
|
40
45
|
"spec/geo_magic/include_calc_spec.rb",
|
41
46
|
"spec/geo_magic/include_remote_spec.rb",
|
42
47
|
"spec/geo_magic/plane_dist_spec.rb",
|
@@ -51,6 +56,7 @@ Gem::Specification.new do |s|
|
|
51
56
|
s.summary = %q{Get your IP and location data and calculate distances on the globe}
|
52
57
|
s.test_files = [
|
53
58
|
"spec/geo_magic/calculate_spec.rb",
|
59
|
+
"spec/geo_magic/geocoder_spec.rb",
|
54
60
|
"spec/geo_magic/include_calc_spec.rb",
|
55
61
|
"spec/geo_magic/include_remote_spec.rb",
|
56
62
|
"spec/geo_magic/plane_dist_spec.rb",
|
data/lib/geo_magic.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
module GeoMap
|
2
|
+
module ServiceAdapter
|
3
|
+
attr_reader :geo_coder, :config
|
4
|
+
|
5
|
+
def geocode location_str
|
6
|
+
raise 'method #geocode must be implemented by adapter subclass'
|
7
|
+
end
|
8
|
+
|
9
|
+
def reverse_geocode latitude, longitude
|
10
|
+
raise 'method #reverse_geocode should be implemented by adapter subclass'
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure path, env = :development
|
14
|
+
@config ||= ::YAML.load_file(path)[env.to_s]
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def google_key
|
20
|
+
config['google_key']
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'geo_magic/geocode/config'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'geocode'
|
4
|
+
require 'graticule'
|
5
|
+
|
6
|
+
module GeoMap
|
7
|
+
class GeoAdapter
|
8
|
+
attr_accessor :service_name, :environment
|
9
|
+
|
10
|
+
def initialize service_name = :google, env = :default
|
11
|
+
setup(env)
|
12
|
+
@service_name = service_name
|
13
|
+
@environment = env
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup env
|
17
|
+
case env
|
18
|
+
when :rails
|
19
|
+
require 'rails/config'
|
20
|
+
self.class.send(:include, RailsServiceAdapter)
|
21
|
+
else
|
22
|
+
self.class.send(:include, ServiceAdapter)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class GraticuleAdapter < GeoAdapter
|
28
|
+
def initialize service_name = :google, env = :default
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def instance
|
33
|
+
@geo_coder ||= ::Graticule.service(service_name).new google_key
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def geocode location_str
|
38
|
+
geo_coder.locate location_str
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class GeocodeAdapter < GeoAdapter
|
43
|
+
def initialize service_name = :google, env = :default
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def instance
|
48
|
+
@geo_coder ||= ::Geocode.new_geocoder service_name, {:google_api_key => google_key}
|
49
|
+
self
|
50
|
+
end
|
51
|
+
|
52
|
+
def geocode location_str
|
53
|
+
geo_coder.geocode(location_str).extend GeocodeAPI
|
54
|
+
end
|
55
|
+
|
56
|
+
module GeocodeAPI
|
57
|
+
def country
|
58
|
+
country_api["CountryNameCode"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def country_name
|
62
|
+
country_api["CountryName"]
|
63
|
+
end
|
64
|
+
|
65
|
+
def state
|
66
|
+
adm_api["AdministrativeAreaName"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def postal_code
|
70
|
+
subadm_api["Locality"]["PostalCode"]["PostalCodeNumber"]
|
71
|
+
end
|
72
|
+
alias_method :zip, :postal_code
|
73
|
+
|
74
|
+
def street
|
75
|
+
subadm_api["Thoroughfare"]["ThoroughfareName"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def city
|
79
|
+
subadm_api["SubAdministrativeAreaName"]
|
80
|
+
end
|
81
|
+
|
82
|
+
def latitude
|
83
|
+
coords[0]
|
84
|
+
end
|
85
|
+
|
86
|
+
def longitude
|
87
|
+
coords[1]
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
|
92
|
+
def api
|
93
|
+
data["Placemark"].first
|
94
|
+
end
|
95
|
+
|
96
|
+
def coords
|
97
|
+
api["Point"]["coordinates"]
|
98
|
+
end
|
99
|
+
|
100
|
+
def adr_api
|
101
|
+
api["AddressDetails"]
|
102
|
+
end
|
103
|
+
|
104
|
+
def country_api
|
105
|
+
adr_api["Country"]
|
106
|
+
end
|
107
|
+
|
108
|
+
def adm_api
|
109
|
+
country_api["AdministrativeArea"]
|
110
|
+
end
|
111
|
+
|
112
|
+
def subadm_api
|
113
|
+
adm_api["SubAdministrativeArea"]
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def reverse_geocode latitude, longitude
|
118
|
+
geo_coder.reverse_geocode "#{latitude}, #{longitude}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
|
123
|
+
class << self
|
124
|
+
def geo_coder options = {:type => :geocode, :service_name => :google}
|
125
|
+
service_name = options[:service_name] || :google
|
126
|
+
type = options[:type] || :geocode
|
127
|
+
env = options[:env]
|
128
|
+
"GeoMap::#{type.to_s.classify}Adapter".constantize.new service_name, env
|
129
|
+
end
|
130
|
+
|
131
|
+
def geocode location_str
|
132
|
+
geo_coder.geocode location_str
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/geo_magic/location.rb
CHANGED
@@ -5,13 +5,18 @@ module GeoMagic
|
|
5
5
|
attr_accessor :ip
|
6
6
|
attr_writer :city, :region, :country
|
7
7
|
|
8
|
-
def
|
8
|
+
def create_from_raw raw_location
|
9
9
|
raw_location.each_pair do |key, value|
|
10
10
|
@city_name = value and next if key == 'city'
|
11
11
|
send :"#{key}=", value
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# TODO
|
16
|
+
def initialize arg
|
17
|
+
create_from_raw arg
|
18
|
+
end
|
19
|
+
|
15
20
|
def [] key
|
16
21
|
send key
|
17
22
|
end
|
data/lib/geo_magic/map_point.rb
CHANGED
@@ -8,9 +8,41 @@ module GeoMagic
|
|
8
8
|
@latitude = latitude
|
9
9
|
@longitude = longitude
|
10
10
|
end
|
11
|
+
|
12
|
+
def move_within distance
|
13
|
+
conversion = GeoDistance.radians_ratio(distance.unit)
|
14
|
+
|
15
|
+
max_radius_rad = dist.distance
|
16
|
+
range = (max_radius_rad * normalize).to_i
|
17
|
+
|
18
|
+
dlong = (get_random_radiant(range) / normalize)
|
19
|
+
dlat = (get_random_radiant(range) / normalize)
|
20
|
+
|
21
|
+
@latitude += dlat
|
22
|
+
@longitude += dlong
|
23
|
+
end
|
24
|
+
|
25
|
+
def move_distance radius
|
26
|
+
distance = radius.distance
|
27
|
+
conversion = GeoDistance.radians_ratio(distance.unit)
|
28
|
+
|
29
|
+
max_radius_rad = distance.distance / conversion
|
30
|
+
range = (max_radius_rad * normalize).to_i
|
31
|
+
|
32
|
+
dlong = (get_random_radiant(range) / normalize) * conversion
|
33
|
+
dlat = (get_random_radiant(range) / normalize) * conversion
|
34
|
+
|
35
|
+
GeoMagic::Point.new dist.latitude + dlat, dist.longitude + dlong
|
36
|
+
end
|
11
37
|
|
12
38
|
def within(distance)
|
13
39
|
GeoMagic::Radius.new self, distance
|
14
40
|
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def get_random_radiant(range)
|
45
|
+
GeoMagic::Radius.get_random_radiant(range)
|
46
|
+
end
|
15
47
|
end
|
16
48
|
end
|
data/lib/geo_magic/point.rb
CHANGED
data/lib/geo_magic/radius.rb
CHANGED
@@ -1,30 +1,53 @@
|
|
1
1
|
module GeoMagic
|
2
2
|
class Radius
|
3
3
|
attr_accessor :center, :distance
|
4
|
-
|
5
|
-
RAD_PER_DEG = 0.017453293
|
6
|
-
|
7
|
-
# radius of the great circle in miles
|
8
|
-
# radius in kilometers...some algorithms use 6367
|
9
|
-
def rad
|
10
|
-
{:km => 6371, :miles => 3956, :feet => 20895592, :meters => 6371000}
|
11
|
-
end
|
12
4
|
|
13
5
|
def initialize center, distance
|
14
6
|
@center = center
|
15
7
|
@distance = distance
|
16
8
|
end
|
17
|
-
|
18
|
-
def create_points number
|
19
|
-
conversion = (RAD_PER_DEG * rad[distance.unit])
|
20
9
|
|
21
|
-
|
10
|
+
# IN BAAAAD !!! need of refactoring and DRYing up!!!
|
11
|
+
|
12
|
+
PI = 3.14159265
|
13
|
+
PI_2 = PI * 2
|
14
|
+
|
15
|
+
def create_point_within mode = :square
|
16
|
+
raise ArgumentError, "mode must be :circle or :square" if ![:circle, :square].include? mode
|
17
|
+
send :"create_point_within_#{mode}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_points_in_square number
|
21
|
+
conversion = GeoDistance.radians_ratio(distance.unit)
|
22
|
+
|
23
|
+
max_radius_rad = distance.distance
|
24
|
+
range = normalize max_radius_rad
|
25
|
+
|
26
|
+
number.times.inject([]) do |res, n|
|
27
|
+
dlong = denormalize get_random_radiant(range)
|
28
|
+
dlat = denormalize get_random_radiant(range)
|
29
|
+
|
30
|
+
point = GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong
|
31
|
+
res << point
|
32
|
+
res
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_points_in_circle number
|
37
|
+
conversion = GeoDistance.radians_ratio(distance.unit)
|
22
38
|
|
23
|
-
|
39
|
+
max_radius_rad = distance.distance
|
40
|
+
range = normalize max_radius_rad
|
41
|
+
|
42
|
+
max_radius_rad = distance.distance
|
43
|
+
range = normalize max_radius_rad
|
24
44
|
|
25
45
|
number.times.inject([]) do |res, n|
|
26
|
-
|
27
|
-
|
46
|
+
q = rand(range) * PI_2
|
47
|
+
r = Math.sqrt(rand(range))
|
48
|
+
|
49
|
+
dlong = denormalize (range * r) * Math.cos(q)
|
50
|
+
dlat = denormalize (range * r) * Math.sin(q)
|
28
51
|
|
29
52
|
point = GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong
|
30
53
|
res << point
|
@@ -32,12 +55,47 @@ module GeoMagic
|
|
32
55
|
end
|
33
56
|
end
|
34
57
|
|
35
|
-
def
|
36
|
-
|
58
|
+
def create_point_within_square
|
59
|
+
conversion = GeoDistance.radians_ratio(distance.unit)
|
60
|
+
|
61
|
+
max_radius_rad = dist.distance
|
62
|
+
range = (max_radius_rad * normalize).to_i
|
63
|
+
|
64
|
+
dlong = (get_random_radiant(range) / normalize)
|
65
|
+
dlat = (get_random_radiant(range) / normalize)
|
66
|
+
|
67
|
+
GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_point_within_circle
|
71
|
+
max_radius_rad = dist.distance
|
72
|
+
range = normalize max_radius_rad
|
73
|
+
|
74
|
+
q = rand(range) * PI_2
|
75
|
+
r = Math.sqrt(rand(range))
|
76
|
+
dlong = denormalize (range * r) * Math.cos(q)
|
77
|
+
dlat = denormalize (range * r) * Math.sin(q)
|
78
|
+
|
79
|
+
GeoMagic::Point.new @center.latitude + dlat, @center.longitude + dlong
|
37
80
|
end
|
81
|
+
|
82
|
+
def get_random_radiant range
|
83
|
+
self.class.get_random_radiant range
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.get_random_radiant range
|
87
|
+
rand(range * 2) - range
|
88
|
+
end
|
89
|
+
|
90
|
+
NORMALIZER = 100.0
|
38
91
|
|
39
|
-
def normalize
|
40
|
-
|
92
|
+
def normalize n
|
93
|
+
(n * NORMALIZER).to_i
|
94
|
+
end
|
95
|
+
|
96
|
+
def denormalize n
|
97
|
+
n / NORMALIZER
|
41
98
|
end
|
99
|
+
|
42
100
|
end
|
43
101
|
end
|
data/lib/geo_magic/util.rb
CHANGED
@@ -20,8 +20,8 @@ module GeoMagic
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class Array
|
23
|
-
def
|
24
|
-
self.extend GeoMagic::
|
23
|
+
def as_map_points
|
24
|
+
self.extend GeoMagic::MapPoints
|
25
25
|
end
|
26
26
|
|
27
27
|
def sort_by_distance
|
@@ -30,7 +30,7 @@ class Array
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module GeoMagic
|
33
|
-
module
|
33
|
+
module MapPoints
|
34
34
|
RAD_PER_DEG = 0.017453293
|
35
35
|
|
36
36
|
def rad
|
data/lib/rails/config.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module GeoMap
|
2
|
+
module RailsServiceAdapter
|
3
|
+
attr_reader :geo_coder
|
4
|
+
|
5
|
+
def geocode location_str
|
6
|
+
raise 'method #geocode must be implemented by adapter subclass'
|
7
|
+
end
|
8
|
+
|
9
|
+
def reverse_geocode latitude, longitude
|
10
|
+
raise 'method #reverse_geocode should be implemented by adapter subclass'
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def env
|
16
|
+
ENV['HEROKU_SITE'] || ::Rails.env.downcase || 'development'
|
17
|
+
end
|
18
|
+
|
19
|
+
def config
|
20
|
+
@config ||= ::YAML.load_file("#{::Rails.root}/config/google_map.yml")[env]
|
21
|
+
end
|
22
|
+
|
23
|
+
def google_key
|
24
|
+
config['google_key']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'geo_magic'
|
3
|
+
|
4
|
+
describe "GeoMagic Geocoder" do
|
5
|
+
before do
|
6
|
+
@geocoder = GeoMap.geo_coder
|
7
|
+
@geocoder.configure File.expand_path('../fixtures/config.yaml', File.dirname(__FILE__)), :development
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should geocode" do
|
11
|
+
location = @geocoder.instance.geocode "Mullerstrasse 9, Munich"
|
12
|
+
location.city.should == 'Munich'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# it "should geocode for rails" do
|
17
|
+
# @geocoder = GeoMap.geo_coder :env => :rails
|
18
|
+
# location = @geocoder.instance.geocode "Mullerstrasse 9, Munich"
|
19
|
+
# location.city.should == 'Munich'
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
|
@@ -9,21 +9,21 @@ describe "GeoMagic closest" do
|
|
9
9
|
|
10
10
|
@center_point = GeoMagic::Point.new @long1, @lat1
|
11
11
|
@radius = @center_point.within(10.km)
|
12
|
-
@points = @radius.
|
12
|
+
@points = @radius.create_points_in_circle 10
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
16
|
it "should select the closest 3 points" do
|
17
17
|
# puts "radius: #{@radius.inspect}"
|
18
18
|
# puts "points: #{@points.inspect}"
|
19
|
-
closest = @points.
|
19
|
+
closest = @points.as_map_points.get_closest 3, :from => @center_point
|
20
20
|
puts "3 closest points: #{closest.inspect}"
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should select all points within 4 km" do
|
24
24
|
# puts "radius: #{@radius.inspect}"
|
25
25
|
# puts "points: #{@points.inspect}"
|
26
|
-
closest = @points.
|
26
|
+
closest = @points.as_map_points.get_within 4.km, :from => @center_point
|
27
27
|
puts "points within 4 km: #{closest.inspect}"
|
28
28
|
end
|
29
29
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-21 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -143,20 +143,22 @@ extensions: []
|
|
143
143
|
|
144
144
|
extra_rdoc_files:
|
145
145
|
- LICENSE.txt
|
146
|
-
- README.
|
146
|
+
- README.textile
|
147
147
|
files:
|
148
148
|
- .document
|
149
149
|
- .rspec
|
150
150
|
- Gemfile
|
151
151
|
- Gemfile.lock
|
152
152
|
- LICENSE.txt
|
153
|
-
- README.
|
153
|
+
- README.textile
|
154
154
|
- Rakefile
|
155
155
|
- VERSION
|
156
156
|
- geo_magic.gemspec
|
157
157
|
- lib/geo_magic.rb
|
158
158
|
- lib/geo_magic/calculate.rb
|
159
159
|
- lib/geo_magic/distance.rb
|
160
|
+
- lib/geo_magic/geocode/config.rb
|
161
|
+
- lib/geo_magic/geocode/geocoder.rb
|
160
162
|
- lib/geo_magic/location.rb
|
161
163
|
- lib/geo_magic/map_point.rb
|
162
164
|
- lib/geo_magic/meta.rb
|
@@ -164,7 +166,10 @@ files:
|
|
164
166
|
- lib/geo_magic/radius.rb
|
165
167
|
- lib/geo_magic/remote.rb
|
166
168
|
- lib/geo_magic/util.rb
|
169
|
+
- lib/rails/config.rb
|
170
|
+
- spec/fixtures/config.yaml
|
167
171
|
- spec/geo_magic/calculate_spec.rb
|
172
|
+
- spec/geo_magic/geocoder_spec.rb
|
168
173
|
- spec/geo_magic/include_calc_spec.rb
|
169
174
|
- spec/geo_magic/include_remote_spec.rb
|
170
175
|
- spec/geo_magic/plane_dist_spec.rb
|
@@ -185,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
190
|
requirements:
|
186
191
|
- - ">="
|
187
192
|
- !ruby/object:Gem::Version
|
188
|
-
hash:
|
193
|
+
hash: -3345832224946490091
|
189
194
|
segments:
|
190
195
|
- 0
|
191
196
|
version: "0"
|
@@ -206,6 +211,7 @@ specification_version: 3
|
|
206
211
|
summary: Get your IP and location data and calculate distances on the globe
|
207
212
|
test_files:
|
208
213
|
- spec/geo_magic/calculate_spec.rb
|
214
|
+
- spec/geo_magic/geocoder_spec.rb
|
209
215
|
- spec/geo_magic/include_calc_spec.rb
|
210
216
|
- spec/geo_magic/include_remote_spec.rb
|
211
217
|
- spec/geo_magic/plane_dist_spec.rb
|