Skip to content

Instantly share code, notes, and snippets.

@korabh
Last active August 29, 2015 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save korabh/9990270 to your computer and use it in GitHub Desktop.
Save korabh/9990270 to your computer and use it in GitHub Desktop.
# Calculate distance between two points.
# 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