class GoogleMapDirections::Directions

Attributes

destination[RW]
json[RW]
origin[RW]
path[RW]
sensor[RW]

Public Class Methods

new(origin, destination, sensor=false) click to toggle source
# 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

Public Instance Methods

destination_address() click to toggle source
# File lib/google_map_directions.rb, line 50
def destination_address
  return @legs['end_address'] unless !status_check
end
destination_coordinates() click to toggle source
# File lib/google_map_directions.rb, line 42
def destination_coordinates
  return @legs['end_location'] unless !status_check
end
distance_as_string() click to toggle source
# File lib/google_map_directions.rb, line 34
def distance_as_string
  return @legs["distance"]["text"] unless !status_check
end
distance_in_meters() click to toggle source
# File lib/google_map_directions.rb, line 38
def distance_in_meters
  return @legs["distance"]["value"] unless !status_check
end
duration_as_string() click to toggle source
# File lib/google_map_directions.rb, line 59
def duration_as_string
  return @legs['duration']['text'] unless !status_check    
end
duration_in_seconds() click to toggle source
# File lib/google_map_directions.rb, line 63
def duration_in_seconds
  return @legs['duration']["value"] unless !status_check   
end
origin_address() click to toggle source
# File lib/google_map_directions.rb, line 46
def origin_address
  return @legs['start_address'] unless !status_check
end
origin_coordinates() click to toggle source
# File lib/google_map_directions.rb, line 54
def origin_coordinates
  return @legs['start_location'] unless !status_check
end
path_length() click to toggle source
# File lib/google_map_directions.rb, line 67
def path_length
  return @path.length unless !status_check
end
polyline() click to toggle source
# File lib/google_map_directions.rb, line 30
def polyline
  return @json["routes"][0]["overview_polyline"]["points"] unless !status_check
end
status() click to toggle source
# File lib/google_map_directions.rb, line 26
def status
  return @json["status"]      
end
step(number) click to toggle source
# File lib/google_map_directions.rb, line 71
def step(number)
  return @path[number] unless !status_check
end

Private Instance Methods

set_up_paths() click to toggle source
# File lib/google_map_directions.rb, line 81
def set_up_paths
  @path = Array.new(@legs["steps"].length)
  count = 0
  @legs["steps"].each do |segment|
    @path[count] = GoogleMapDirections::Step.new(segment["distance"], segment["duration"], segment["end_location"], segment["start_location"], count, segment["html_instructions"])
    count = count + 1
  end
end
status_check() click to toggle source
# File lib/google_map_directions.rb, line 77
def status_check
  status == 'OK'
end