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 lookup in geo_lat_lng_smt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeoLatLng

Instance variables



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

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



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

def addr
  @addr
end

#base_jsonObject (readonly)

Base address for Google maps api



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

def base_json
  @base_json
end

#default_intObject (readonly)

Default International set to GMT Museum



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

def default_int
  @default_int
end

#default_usObject (readonly)

Default US set to PARCS



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

def default_us
  @default_us
end

#latObject

Latitude returned



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

def lat
  @lat
end

#lngObject

Longitude returned



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

def lng
  @lng
end

Instance Method Details

#set_coordinatesObject

coordinates lookup



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

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