title: How to calculate distance using lists of coordinates with Google Maps Roads API
body: <p>I'm generating static map with <strong>snapToRoads</strong> (since it accepts multiple waypoints).</p>
  
  <p>Given I have lists of coordinates, how can I calculate distance between  those coordinates and sum it to get <strong>total driving distance</strong>.</p>
  
  <p>Or is there other better way to do it in <strong>ruby code</strong> ?</p>
  
  <p>Sample snap-to-roads request:</p>
  
  <pre><code>waypoints = [arrays of coordinates]
  snap_to_roads_url = "https://roads.googleapis.com/v1/snapToRoads?path=#{waypoints.join('|')}&amp;interpolate=true&amp;key=API_KEY"
  snappedPoints = HTTParty.get(URI.encode(snap_to_roads_url))
  
  # Store snapped polyline returned by the snap-to-road service
  snappedPoints['snappedPoints'].each do |snap|
    snappedCoordinates &lt;&lt; "#{snap['location']['latitude']},#{snap['location']['longitude']}"
    placeIdArray &lt;&lt; snap['placeId']
  end
  </code></pre>
  
  <p>Static Map request:</p>
  
  <pre><code>https://maps-api-ssl.google.com/maps/api/staticmap?&amp;size=650x550&amp;sensor=false&amp;zoom=16&amp;markers=size:small&amp;maptype=roadmap&amp;path=weight:3%7Ccolor:red%7C54.57424022982199,-1.2351261042386523|54.57423420000001,-1.2351275000000002|54.57423420000001,-1.2351275000000002 ...many more
  </code></pre>
  
  <p>And also any idea how can I include <strong>markers</strong> with the above request, given I have <strong>origin and destination coordinates</strong>.</p>
  
  <p>Please help!</p>