Class: GeoLatLng

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

Overview

class for location lookup in geo_lat_lng_smt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeoLatLng

Instance variables



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/eot/geo_lat_lng_smt.rb', line 30

def initialize
     
  @base           = "http://maps.googleapis.com/maps/api/geocode/json?address="
  # @base           = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address="
  @default_us     = "3333 Coyote Hill Road, Palo Alto, CA, 94304, USA"#do you copy? :D
  @default_int    = "Blackheath Ave, London SE10 8XJ, UK"
  @lat            = 0.0
  @lng            = 0.0
  # MultiXml.parser = :rexml#:libxml#:ox # :nokogiri
  @addr = @default_int
  
end

Instance Attribute Details

#addrObject

Address entered



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

def addr
  @addr
end

#baseObject (readonly)

Base address for Google maps api



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

def base
  @base
end

#default_intObject (readonly)

Default International set to GMT Museum



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

def default_int
  @default_int
end

#default_usObject (readonly)

Default US set to PARCS



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

def default_us
  @default_us
end

#latObject

Latitude returned



24
25
26
# File 'lib/eot/geo_lat_lng_smt.rb', line 24

def lat
  @lat
end

#lngObject

Longitude returned



27
28
29
# File 'lib/eot/geo_lat_lng_smt.rb', line 27

def lng
  @lng
end

Instance Method Details

#get_coordinates_from_addressObject

coordinates lookup



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/eot/geo_lat_lng_smt.rb', line 49

def get_coordinates_from_address
  addr         = URI.escape( @base + @addr )      
  resrc        = RestClient.get( addr )     
  parsed_resrc = JSON.parse(resrc)#MultiXml.parse( res )
  #~ result     = parsed_res[ "GeocodeResponse" ][ "result" ]
  results     = parsed_resrc["results"] 
  #~ status     = parsed_res#[ "GeocodeResponse" ][ "status" ] 
  status     = parsed_resrc[ "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