gmaps_gem 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/gmaps_gem.rb +33 -0
  2. metadata +56 -0
data/lib/gmaps_gem.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ class ActiveRecord::Base
6
+ class << self
7
+ def geocode(address)
8
+ url = "http://maps.googleapis.com/maps/api/geocode/json?address=#{address}&sensor=true"
9
+ resp = Net::HTTP.get_response(URI.parse(url))
10
+ data = resp.body
11
+ result = JSON.parse(data)
12
+ #if result.has_key? 'Error'
13
+ # raise "web service error"
14
+ #end
15
+ a = result
16
+ lat = a["results"].first["geometry"]["location"]["lat"]
17
+ lng = a["results"].first["geometry"]["location"]["lng"]
18
+ latlng = [lat,lng]
19
+ end
20
+
21
+ def reverse_geocode(lat,lng)
22
+ url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=#{lat},#{lng}&sensor=true"
23
+ resp = Net::HTTP.get_response(URI.parse(url))
24
+ data = resp.body
25
+ result = JSON.parse(data)
26
+
27
+ a = result
28
+ address = a["results"].first["address_components"].first["long_name"] #.first["address_components"]["long_name"]
29
+ puts address
30
+ end
31
+ end
32
+ end
33
+
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmaps_gem
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - martin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-02 00:00:00 +08:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A gem to for geocoding...
18
+ email: fx_great@yahoo.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - lib/gmaps_gem.rb
27
+ has_rdoc: true
28
+ homepage: http://rubygems.org/gems/gmaps_gem
29
+ licenses: []
30
+
31
+ post_install_message:
32
+ rdoc_options: []
33
+
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ requirements: []
49
+
50
+ rubyforge_project:
51
+ rubygems_version: 1.6.2
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: Google Maps Gem.
55
+ test_files: []
56
+