Class: GeoLatLng

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

Overview

class GeoLatLng file = geo_lat_lng_smt.rb class for location coordinates lookup

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeoLatLng

Instance variables



23
24
25
26
27
28
29
30
# File 'lib/eot/geo_lat_lng_smt.rb', line 23

def initialize
  @base_json      = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address='
  @default_us     = '3333 Coyote Hill Road, Palo Alto, CA, 94304, USA'
  @default_int    = 'Blackheath Ave, London SE10 8XJ, UK'
  @addr           = @default_int
  @lat            = 0.0
  @lng            = 0.0
end

Instance Attribute Details

#addrObject

Address entered



14
15
16
# File 'lib/eot/geo_lat_lng_smt.rb', line 14

def addr
  @addr
end

#base_jsonObject (readonly)

Base address for Google maps api



5
6
7
# File 'lib/eot/geo_lat_lng_smt.rb', line 5

def base_json
  @base_json
end

#default_intObject (readonly)

Default International set to GMT Museum



11
12
13
# File 'lib/eot/geo_lat_lng_smt.rb', line 11

def default_int
  @default_int
end

#default_usObject (readonly)

Default US set to PARCS



8
9
10
# File 'lib/eot/geo_lat_lng_smt.rb', line 8

def default_us
  @default_us
end

#latObject

Latitude returned



17
18
19
# File 'lib/eot/geo_lat_lng_smt.rb', line 17

def lat
  @lat
end

#lngObject

Longitude returned



20
21
22
# File 'lib/eot/geo_lat_lng_smt.rb', line 20

def lng
  @lng
end

Instance Method Details

#set_coordinatesObject

coordinates lookup



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/eot/geo_lat_lng_smt.rb', line 33

def set_coordinates
  addr = Addressable::URI.escape(@base_json + @addr)
  rest_resource = JSON.parse(RestClient.get(addr))
  results       = rest_resource['results']
  status        = rest_resource['status']
  if status != 'OK'
    @addr = @default_int
  else
    @lat   = results[0]['geometry']['location']['lat'].to_f
    @lng  = results[0]['geometry']['location']['lng'].to_f
  end
end