Skip to content

Instantly share code, notes, and snippets.

@mauriciozaffari
Created December 1, 2010 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciozaffari/723942 to your computer and use it in GitHub Desktop.
Save mauriciozaffari/723942 to your computer and use it in GitHub Desktop.
require "json"
require "open-uri"
require "googlemaps_polyline"
start = "Chicago"
stop = "Texas"
request_str = "http://maps.googleapis.com/maps/api/directions/json?sensor=false&alternatives=true&"
request_str += "origin=#{URI.encode start}&"
request_str += "destination=#{URI.encode stop}"
response = open(request_str)
json_path = JSON.parse(response.read)
polyline = []
path_json["routes"][0]["legs"][0]["steps"].each do |step|
points = step["polyline"]["points"]
levels = step["polyline"]["levels"]
polyline_data = GoogleMapsPolyline.decode_polyline(points, levels)
polyline_data.collect do |point|
polyline.push([point[0], point[1]])
end
end
polyline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment