Class: Machiawase::Place

Inherits:
Object
  • Object
show all
Includes:
Geocoder
Defined in:
lib/machiawase/place.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#addressString (readonly)

Returns the address.

Returns:

  • (String)

    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_urlString (readonly)

Returns the url of Google Map.

Returns:

  • (String)

    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

#latObject

Returns the latitude.

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

#lonObject

Returns the longitude.

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

.configureObject


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

.geocode(address) ⇒ Hash

Returns geocode of given address.

Returns:

  • (Hash)

    geocode of given address.


38
39
40
41
42
43
44
# File 'lib/machiawase/place.rb', line 38

def self.geocode(address)
  Place.configure
  lat, lon = Geocoder.coordinates(address)
  {"lat" => lat, "lon" => lon}
rescue => exc
  p exc
end

Instance Method Details

#to_hHash

Returns attributes with Hash format.

Returns:

  • (Hash)

    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_jsonJSON

Returns attributes with JSON format.

Returns:

  • (JSON)

    attributes with JSON format.


71
72
73
# File 'lib/machiawase/place.rb', line 71

def to_json
  JSON.pretty_generate(to_h)
end

#to_msgpackObject


75
76
77
# File 'lib/machiawase/place.rb', line 75

def to_msgpack
  to_h.to_msgpack
end