Class: GeoLatLng
- Inherits:
-
Object
- Object
- GeoLatLng
- 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
-
#addr ⇒ Object
Address entered.
-
#base_json ⇒ Object
readonly
Base address for Google maps api.
-
#default_int ⇒ Object
readonly
Default International set to GMT Museum.
-
#default_us ⇒ Object
readonly
Default US set to PARCS.
-
#lat ⇒ Object
Latitude returned.
-
#lng ⇒ Object
Longitude returned.
Instance Method Summary collapse
-
#initialize ⇒ GeoLatLng
constructor
Instance variables.
-
#set_coordinates ⇒ Object
coordinates lookup.
Constructor Details
#initialize ⇒ GeoLatLng
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
#addr ⇒ Object
Address entered
15 16 17 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 15 def addr @addr end |
#base_json ⇒ Object (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_int ⇒ Object (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_us ⇒ Object (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 |
#lat ⇒ Object
Latitude returned
18 19 20 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 18 def lat @lat end |
#lng ⇒ Object
Longitude returned
21 22 23 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 21 def lng @lng end |
Instance Method Details
#set_coordinates ⇒ Object
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 |