Class: GoogleMapDirections::Directions
- Inherits:
-
Object
- Object
- GoogleMapDirections::Directions
- Defined in:
- lib/google_map_directions.rb
Constant Summary collapse
- @@base_google_url =
'http://maps.googleapis.com/maps/api/directions/json?'
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#sensor ⇒ Object
Returns the value of attribute sensor.
Instance Method Summary collapse
- #destination_address ⇒ Object
- #destination_coordinates ⇒ Object
- #distance_as_string ⇒ Object
- #distance_in_meters ⇒ Object
- #duration_as_string ⇒ Object
- #duration_in_minutes ⇒ Object
-
#initialize(origin, destination, sensor = false) ⇒ Directions
constructor
A new instance of Directions.
- #origin_address ⇒ Object
- #origin_coordinates ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(origin, destination, sensor = false) ⇒ Directions
Returns a new instance of Directions.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/google_map_directions.rb', line 13 def initialize(origin, destination, sensor = false) @origin = origin.gsub(/\s/,'+') @destination = destination.gsub(/\s/,'+') @sensor = sensor.to_s url = "#{@@base_google_url}&origin=#{@origin}&destination=#{@destination}&sensor=#{@sensor}" @json = JSON.parse(open(url).read) @legs = (status_check ? @json["routes"][0]["legs"][0] : nil) @paths = nil set_up_paths end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
9 10 11 |
# File 'lib/google_map_directions.rb', line 9 def destination @destination end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
10 11 12 |
# File 'lib/google_map_directions.rb', line 10 def json @json end |
#origin ⇒ Object
Returns the value of attribute origin.
9 10 11 |
# File 'lib/google_map_directions.rb', line 9 def origin @origin end |
#sensor ⇒ Object
Returns the value of attribute sensor.
9 10 11 |
# File 'lib/google_map_directions.rb', line 9 def sensor @sensor end |
Instance Method Details
#destination_address ⇒ Object
44 45 46 |
# File 'lib/google_map_directions.rb', line 44 def destination_address if status_check then return @legs['end_address'] else return nil end end |
#destination_coordinates ⇒ Object
36 37 38 |
# File 'lib/google_map_directions.rb', line 36 def destination_coordinates if status_check then return @legs['end_location'] else return nil end end |
#distance_as_string ⇒ Object
28 29 30 |
# File 'lib/google_map_directions.rb', line 28 def distance_as_string if status_check then return @legs["distance"]["text"] else return nil end end |
#distance_in_meters ⇒ Object
32 33 34 |
# File 'lib/google_map_directions.rb', line 32 def distance_in_meters if status_check then return @legs["distance"]["value"] else return nil end end |
#duration_as_string ⇒ Object
53 54 55 |
# File 'lib/google_map_directions.rb', line 53 def duration_as_string if status_check then return @legs['duration']['text'] else return nil end end |
#duration_in_minutes ⇒ Object
57 58 59 |
# File 'lib/google_map_directions.rb', line 57 def duration_in_minutes if status_check then return @legs['duration']["value"] else return nil end end |
#origin_address ⇒ Object
40 41 42 |
# File 'lib/google_map_directions.rb', line 40 def origin_address if status_check then return @legs['start_address'] else return nil end end |
#origin_coordinates ⇒ Object
48 49 50 |
# File 'lib/google_map_directions.rb', line 48 def origin_coordinates if status_check then return @legs['start_location'] else return nil end end |
#status ⇒ Object
24 25 26 |
# File 'lib/google_map_directions.rb', line 24 def status return @json["status"] end |