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 coordinates lookup
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
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
#addr ⇒ Object
Address entered
14 15 16 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 14 def addr @addr end |
#base_json ⇒ Object (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_int ⇒ Object (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_us ⇒ Object (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 |
#lat ⇒ Object
Latitude returned
17 18 19 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 17 def lat @lat end |
#lng ⇒ Object
Longitude returned
20 21 22 |
# File 'lib/eot/geo_lat_lng_smt.rb', line 20 def lng @lng end |
Instance Method Details
#set_coordinates ⇒ Object
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 |