locationator 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/lib/locationator/version.rb +3 -0
- data/lib/locationator.rb +62 -0
- data/locationator.gemspec +23 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODU4NTAyYjIzMmY5MDIxMmFiYWY3MDBjZGJiOWQwMTMyYmYyYjRmNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzE0NGQ0ZjhmNzE0ZTEyYWQyNDA4YmQ2ZWE1ZjFhMDZhZTljODI4MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NGU1ODBlODVmOGRlNTYyNzAxYWY3YWQyYmJjMjNhZjU2MmYwYTI2ZmM1Yjcy
|
10
|
+
NzhhNTMxYjgxMGI2ODgwMGFiYzU1ZWQ3NDk4MWRlM2QxNDM2ZGM1MGI3ZmZk
|
11
|
+
ZDg5MjUxM2RhMTZhODMyZmNhZWY1NDE3MzlmMWE1YjYxMGIwNDc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTYxOTBkNDEyMDc4OGVkMzlmYWQ2Mzk3MWEwYzEzNmUxNTk1YjhkMjZlODdj
|
14
|
+
NDU4NjYyOGRiOTg3NTNlMTA3MWVhZDM0YWE3NGE5MDNkNGUyYjdkNGQwMGFj
|
15
|
+
MmM3OTI3OTU2MDk0YjIxNzM3NDAwZjAwNDM1YjU1OTBjNTBjOTk=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lawrence Davis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
A lightweight geocoder gem that returns an array of the latitude and longitude for an address.
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'locationator'
|
8
|
+
|
9
|
+
And then execute:
|
10
|
+
|
11
|
+
$ bundle
|
12
|
+
|
13
|
+
Or install it yourself as:
|
14
|
+
|
15
|
+
$ gem install locationator
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
There are 3 methods in this gem:
|
20
|
+
|
21
|
+
Location.lat("800 W. Huron St Chicago, IL")
|
22
|
+
|
23
|
+
will return the latitude.
|
24
|
+
|
25
|
+
Location.lng("800 W. Huron St Chicago, IL")
|
26
|
+
|
27
|
+
will return the longitude
|
28
|
+
|
29
|
+
Location.lat_lng("800 W. Huron St Chicago, IL")
|
30
|
+
|
31
|
+
will return an array of the latitude and longitude.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/locationator.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'locationator/version'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module Locationator
|
7
|
+
|
8
|
+
# Returns the latitude
|
9
|
+
def self.lat(address)
|
10
|
+
geocodeURL = get_url(address)
|
11
|
+
geocodeResponse = get_data(geocodeURL)
|
12
|
+
lat = geocodeResponse["results"][0]["geometry"]["location"]["lat"]
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the longitude
|
16
|
+
def self.lng(address)
|
17
|
+
geocodeURL = get_url(address)
|
18
|
+
geocodeResponse = get_data(geocodeURL)
|
19
|
+
lng = geocodeResponse["results"][0]["geometry"]["location"]["lng"]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Builds an array of the latitude and longitude
|
23
|
+
def self.lat_lng(address)
|
24
|
+
lat_lng_array = []
|
25
|
+
lat_lng_array.push(self.lat(address))
|
26
|
+
lat_lng_array.push(self.lng(address))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns the zip code for an address
|
30
|
+
def self.zip(address)
|
31
|
+
geocodeURL = get_url(address)
|
32
|
+
geocodeResponse = get_data(geocodeURL)
|
33
|
+
components = geocodeResponse["results"][0]["address_components"]
|
34
|
+
# The postal code is always the last address component returned
|
35
|
+
# TODO: Find a cleaner method of finding the postal code in the JSON
|
36
|
+
zip = components[components.length - 1]["long_name"]
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns a properly formatted address
|
40
|
+
def self.format(address)
|
41
|
+
geocodeURL = get_url(address)
|
42
|
+
geocodeResponse = get_data(geocodeURL)
|
43
|
+
formatted = geocodeResponse["results"][0]["formatted_address"]
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Builds the URL that we need to get our JSON response from Google
|
49
|
+
def self.get_url(address)
|
50
|
+
geocodePrimary = "http://maps.googleapis.com/maps/api/geocode/json?address="
|
51
|
+
geocodeAddress = URI::encode(address)
|
52
|
+
geocodeSensor = "&sensor=false"
|
53
|
+
geocodeURL = geocodePrimary + geocodeAddress + geocodeSensor
|
54
|
+
end
|
55
|
+
|
56
|
+
# Sends the URL to Google and parses the response
|
57
|
+
def self.get_data(url)
|
58
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
59
|
+
data = JSON.parse(response.body)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'locationator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "locationator"
|
8
|
+
spec.version = Locationator::VERSION
|
9
|
+
spec.authors = ["Lawrence Davis"]
|
10
|
+
spec.email = ["lawrence@lrdiv.com"]
|
11
|
+
spec.description = %q{Get location information.}
|
12
|
+
spec.summary = %q{Use Google's geocoding services to get information about any address.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locationator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lawrence Davis
|
@@ -44,7 +44,16 @@ email:
|
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
|
-
files:
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- Gemfile.lock
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- lib/locationator.rb
|
55
|
+
- lib/locationator/version.rb
|
56
|
+
- locationator.gemspec
|
48
57
|
homepage: ''
|
49
58
|
licenses:
|
50
59
|
- MIT
|