Class: MapLocation

Inherits:
Object
  • Object
show all
Defined in:
lib/googlestaticmap.rb

Overview

Container class for a location on the map. Set either a latitude and longitude, or an address

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ MapLocation

Returns a new instance of MapLocation.



220
221
222
# File 'lib/googlestaticmap.rb', line 220

def initialize(attrs={})
  attrs.each {|k,v| self.send("#{k}=".to_sym,v.to_s)}
end

Instance Attribute Details

#addressObject

String address - can be a full address, city name, zip code, etc. This is ignored if latitude and longitude are set.



218
219
220
# File 'lib/googlestaticmap.rb', line 218

def address
  @address
end

#latitudeObject

Decimal degrees, positive is north



211
212
213
# File 'lib/googlestaticmap.rb', line 211

def latitude
  @latitude
end

#longitudeObject

Decimal degrees, positive is east



214
215
216
# File 'lib/googlestaticmap.rb', line 214

def longitude
  @longitude
end

Instance Method Details

#to_sObject



224
225
226
227
228
229
230
231
232
# File 'lib/googlestaticmap.rb', line 224

def to_s
  if latitude && longitude
    "#{CGI.escape(latitude.to_s)},#{CGI.escape(longitude.to_s)}"
  elsif address
    CGI.escape(address)
  else
    raise Exception.new("Need to set either latitude and longitude, or address")
  end
end