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
Returns the value of attribute json.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#path ⇒ Object
Returns the value of attribute path.
-
#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_seconds ⇒ Object
-
#initialize(origin, destination, sensor = false) ⇒ Directions
constructor
A new instance of Directions.
- #origin_address ⇒ Object
- #origin_coordinates ⇒ Object
- #path_length ⇒ Object
- #polyline ⇒ Object
- #status ⇒ Object
- #step(number) ⇒ Object
Constructor Details
#initialize(origin, destination, sensor = false) ⇒ Directions
Returns a new instance of Directions.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/google_map_directions.rb', line 11 def initialize(origin, destination, sensor=false) @origin = origin @destination = destination @sensor = sensor url = "#{@@base_google_url}&origin=#{@origin.gsub(/\s/,'+')}&destination=#{@destination.gsub(/\s/,'+')}&sensor=#{@sensor.to_s}" @json = JSON.parse(open(url).read) if status_check @legs = @json["routes"][0]["legs"][0] set_up_paths else @legs = nil @path = nil end end |
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination.
8 9 10 |
# File 'lib/google_map_directions.rb', line 8 def destination @destination end |
#json ⇒ Object
Returns the value of attribute json.
8 9 10 |
# File 'lib/google_map_directions.rb', line 8 def json @json end |
#origin ⇒ Object
Returns the value of attribute origin.
8 9 10 |
# File 'lib/google_map_directions.rb', line 8 def origin @origin end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/google_map_directions.rb', line 8 def path @path end |
#sensor ⇒ Object
Returns the value of attribute sensor.
8 9 10 |
# File 'lib/google_map_directions.rb', line 8 def sensor @sensor end |
Instance Method Details
#destination_address ⇒ Object
50 51 52 |
# File 'lib/google_map_directions.rb', line 50 def destination_address return @legs['end_address'] unless !status_check end |
#destination_coordinates ⇒ Object
42 43 44 |
# File 'lib/google_map_directions.rb', line 42 def destination_coordinates return @legs['end_location'] unless !status_check end |
#distance_as_string ⇒ Object
34 35 36 |
# File 'lib/google_map_directions.rb', line 34 def distance_as_string return @legs["distance"]["text"] unless !status_check end |
#distance_in_meters ⇒ Object
38 39 40 |
# File 'lib/google_map_directions.rb', line 38 def distance_in_meters return @legs["distance"]["value"] unless !status_check end |
#duration_as_string ⇒ Object
59 60 61 |
# File 'lib/google_map_directions.rb', line 59 def duration_as_string return @legs['duration']['text'] unless !status_check end |
#duration_in_seconds ⇒ Object
63 64 65 |
# File 'lib/google_map_directions.rb', line 63 def duration_in_seconds return @legs['duration']["value"] unless !status_check end |
#origin_address ⇒ Object
46 47 48 |
# File 'lib/google_map_directions.rb', line 46 def origin_address return @legs['start_address'] unless !status_check end |
#origin_coordinates ⇒ Object
54 55 56 |
# File 'lib/google_map_directions.rb', line 54 def origin_coordinates return @legs['start_location'] unless !status_check end |
#path_length ⇒ Object
67 68 69 |
# File 'lib/google_map_directions.rb', line 67 def path_length return @path.length unless !status_check end |
#polyline ⇒ Object
30 31 32 |
# File 'lib/google_map_directions.rb', line 30 def polyline return @json["routes"][0]["overview_polyline"]["points"] unless !status_check end |
#status ⇒ Object
26 27 28 |
# File 'lib/google_map_directions.rb', line 26 def status return @json["status"] end |
#step(number) ⇒ Object
71 72 73 |
# File 'lib/google_map_directions.rb', line 71 def step(number) return @path[number] unless !status_check end |