Advertisement
Guest User

Untitled

a guest
May 24th, 2015
619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.72 KB | None | 0 0
  1. class CheckPoint < ActiveRecord::Base
  2.   belongs_to :trip
  3.  
  4.   def self.create_path(path, trip)
  5.     api_key = 'AIzaSyDRljTMN1vNOQL2zxIMh93xA2yni1akkqU'
  6.     path.each do |point|
  7.       path_str += point[:latitude].to_s + ',' + point[:longitude].to_s
  8.       if point != path.last
  9.         path_str  += '|'
  10.       end
  11.     end
  12.     result = Net::HTTP.get(URI.parse('https://roads.googleapis.com/v1/snapToRoads?' + path_str + '&interpolate=true' + '&key=' + api_key ))
  13.  
  14.  
  15.     ActiveSupport::JSON.decode(result)["snappedPoints"].each do |point|
  16.       CheckPoint.create(longitude: point["location"]["longitude"],
  17.                         latitude: point["location"]["latitude"],
  18.                         trip: trip)
  19.     end
  20.   end
  21. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement