Skip to content

Instantly share code, notes, and snippets.

@harshamv
Forked from korabh/distance.rb
Created June 30, 2014 19:06
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 harshamv/7161be10c31384225a15 to your computer and use it in GitHub Desktop.
Save harshamv/7161be10c31384225a15 to your computer and use it in GitHub Desktop.
# Google Direction API
include HTTParty
format :json
def api_key
# Your API key
end
def direciton_api_url
'https://maps.googleapis.com/maps/api/distancematrix/'
end
def user_coords
(cookies["coords"].gsub! '/', ',')
end
def join_loan_adress(loan)
[loan.latitude, loan.longitude].join(",").to_s
end
def loan_addresses
join_loan_adress(@loan)
end
# API Request
def get_data
response = JSON.parse HTTParty.get("#{direciton_api_url}json?origins=#{user_coords}&destinations=#{loan_addresses}&mode=driving&sensor=false&key=#{api_key}").response.body
end
def result
"#{direciton_api_url}json?origins=#{user_coords}&destinations=#{loan_addresses}&mode=driving&sensor=false&key=#{api_key}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment