Class: GoogleMapDirections::Directions

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#destinationObject

Returns the value of attribute destination.



9
10
11
# File 'lib/google_map_directions.rb', line 9

def destination
  @destination
end

#jsonObject (readonly)

Returns the value of attribute json.



10
11
12
# File 'lib/google_map_directions.rb', line 10

def json
  @json
end

#originObject

Returns the value of attribute origin.



9
10
11
# File 'lib/google_map_directions.rb', line 9

def origin
  @origin
end

#sensorObject

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_addressObject



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_coordinatesObject



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_stringObject



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_metersObject



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_stringObject



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_minutesObject



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_addressObject



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_coordinatesObject



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

#statusObject



24
25
26
# File 'lib/google_map_directions.rb', line 24

def status
  return @json["status"]      
end