Class: Machiawase::Place
- Inherits:
-
Object
- Object
- Machiawase::Place
- Includes:
- Geocoder
- Defined in:
- lib/machiawase/place.rb
Instance Attribute Summary collapse
-
#address ⇒ String
readonly
The address.
-
#google_map_url ⇒ String
readonly
The url of Google Map.
-
#lat ⇒ Object
The latitude.
-
#lon ⇒ Object
The longitude.
Class Method Summary collapse
- .configure ⇒ Object
-
.geocode(address) ⇒ Hash
Geocode of given address.
Instance Method Summary collapse
-
#initialize(lat, lon) ⇒ Place
constructor
A new instance of Place.
-
#to_h ⇒ Hash
Attributes with Hash format.
-
#to_json ⇒ JSON
Attributes with JSON format.
- #to_msgpack ⇒ Object
Constructor Details
#initialize(lat, lon) ⇒ Place
Returns a new instance of Place.
18 19 20 21 22 23 24 25 |
# File 'lib/machiawase/place.rb', line 18 def initialize(lat, lon) @lat = lat @lon = lon @address = nil @google_map_url = "http://maps.google.co.jp/maps?q=#{@lat},#{@lon}&ll=#{@lat},#{@lon}&z=14&t=m&brcurrent=3,0x0:0x0,1" @proxy = Machiawase.parse_proxy(ENV["http_proxy"]) Place.configure end |
Instance Attribute Details
#address ⇒ String (readonly)
Returns the address.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/machiawase/place.rb', line 12 class Place include Geocoder attr_reader :address, :google_map_url attr_accessor :lat, :lon def initialize(lat, lon) @lat = lat @lon = lon @address = nil @google_map_url = "http://maps.google.co.jp/maps?q=#{@lat},#{@lon}&ll=#{@lat},#{@lon}&z=14&t=m&brcurrent=3,0x0:0x0,1" @proxy = Machiawase.parse_proxy(ENV["http_proxy"]) Place.configure end def lat=(val) @lat = val @address = nil end def lon=(val) @lon = val @address = nil end # @return [Hash] geocode of given address. def self.geocode(address) Place.configure lat, lon = Geocoder.coordinates(address) {"lat" => lat, "lon" => lon} rescue => exc p exc end def self.configure Geocoder.configure( :language => :ja, :http_proxy => ENV["http_proxy"] ) end def address Place.configure @address ||= Geocoder.address([@lat, @lon]) rescue => exc p exc end # @return [Hash] attributes with Hash format. def to_h { "latitude" => @lat, "longitude" => @lon, "address" => address, "google_map" => @google_map_url } end # @return [JSON] attributes with JSON format. def to_json JSON.pretty_generate(to_h) end def to_msgpack to_h.to_msgpack end end |
#google_map_url ⇒ String (readonly)
Returns the url of Google Map.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/machiawase/place.rb', line 12 class Place include Geocoder attr_reader :address, :google_map_url attr_accessor :lat, :lon def initialize(lat, lon) @lat = lat @lon = lon @address = nil @google_map_url = "http://maps.google.co.jp/maps?q=#{@lat},#{@lon}&ll=#{@lat},#{@lon}&z=14&t=m&brcurrent=3,0x0:0x0,1" @proxy = Machiawase.parse_proxy(ENV["http_proxy"]) Place.configure end def lat=(val) @lat = val @address = nil end def lon=(val) @lon = val @address = nil end # @return [Hash] geocode of given address. def self.geocode(address) Place.configure lat, lon = Geocoder.coordinates(address) {"lat" => lat, "lon" => lon} rescue => exc p exc end def self.configure Geocoder.configure( :language => :ja, :http_proxy => ENV["http_proxy"] ) end def address Place.configure @address ||= Geocoder.address([@lat, @lon]) rescue => exc p exc end # @return [Hash] attributes with Hash format. def to_h { "latitude" => @lat, "longitude" => @lon, "address" => address, "google_map" => @google_map_url } end # @return [JSON] attributes with JSON format. def to_json JSON.pretty_generate(to_h) end def to_msgpack to_h.to_msgpack end end |
#lat ⇒ Object
Returns the latitude.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/machiawase/place.rb', line 12 class Place include Geocoder attr_reader :address, :google_map_url attr_accessor :lat, :lon def initialize(lat, lon) @lat = lat @lon = lon @address = nil @google_map_url = "http://maps.google.co.jp/maps?q=#{@lat},#{@lon}&ll=#{@lat},#{@lon}&z=14&t=m&brcurrent=3,0x0:0x0,1" @proxy = Machiawase.parse_proxy(ENV["http_proxy"]) Place.configure end def lat=(val) @lat = val @address = nil end def lon=(val) @lon = val @address = nil end # @return [Hash] geocode of given address. def self.geocode(address) Place.configure lat, lon = Geocoder.coordinates(address) {"lat" => lat, "lon" => lon} rescue => exc p exc end def self.configure Geocoder.configure( :language => :ja, :http_proxy => ENV["http_proxy"] ) end def address Place.configure @address ||= Geocoder.address([@lat, @lon]) rescue => exc p exc end # @return [Hash] attributes with Hash format. def to_h { "latitude" => @lat, "longitude" => @lon, "address" => address, "google_map" => @google_map_url } end # @return [JSON] attributes with JSON format. def to_json JSON.pretty_generate(to_h) end def to_msgpack to_h.to_msgpack end end |
#lon ⇒ Object
Returns the longitude.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/machiawase/place.rb', line 12 class Place include Geocoder attr_reader :address, :google_map_url attr_accessor :lat, :lon def initialize(lat, lon) @lat = lat @lon = lon @address = nil @google_map_url = "http://maps.google.co.jp/maps?q=#{@lat},#{@lon}&ll=#{@lat},#{@lon}&z=14&t=m&brcurrent=3,0x0:0x0,1" @proxy = Machiawase.parse_proxy(ENV["http_proxy"]) Place.configure end def lat=(val) @lat = val @address = nil end def lon=(val) @lon = val @address = nil end # @return [Hash] geocode of given address. def self.geocode(address) Place.configure lat, lon = Geocoder.coordinates(address) {"lat" => lat, "lon" => lon} rescue => exc p exc end def self.configure Geocoder.configure( :language => :ja, :http_proxy => ENV["http_proxy"] ) end def address Place.configure @address ||= Geocoder.address([@lat, @lon]) rescue => exc p exc end # @return [Hash] attributes with Hash format. def to_h { "latitude" => @lat, "longitude" => @lon, "address" => address, "google_map" => @google_map_url } end # @return [JSON] attributes with JSON format. def to_json JSON.pretty_generate(to_h) end def to_msgpack to_h.to_msgpack end end |
Class Method Details
.configure ⇒ Object
46 47 48 49 50 51 |
# File 'lib/machiawase/place.rb', line 46 def self.configure Geocoder.configure( :language => :ja, :http_proxy => ENV["http_proxy"] ) end |
Instance Method Details
#to_h ⇒ Hash
Returns attributes with Hash format.
61 62 63 64 65 66 67 68 |
# File 'lib/machiawase/place.rb', line 61 def to_h { "latitude" => @lat, "longitude" => @lon, "address" => address, "google_map" => @google_map_url } end |
#to_json ⇒ JSON
Returns attributes with JSON format.
71 72 73 |
# File 'lib/machiawase/place.rb', line 71 def to_json JSON.pretty_generate(to_h) end |
#to_msgpack ⇒ Object
75 76 77 |
# File 'lib/machiawase/place.rb', line 75 def to_msgpack to_h.to_msgpack end |