Last active
August 29, 2015 13:58
-
-
Save korabh/9990270 to your computer and use it in GitHub Desktop.
# Calculate distance between two points.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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