Created
May 6, 2013 20:28
-
-
Save rajdeep26/5527923 to your computer and use it in GitHub Desktop.
This Ruby code gives output as the list of similar places for the given keyword. The results are fetched from the Google Maps using Google Maps Places API.
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
require "net/http" | |
require "json" | |
def Findplaces(keyword) | |
keyword=keyword.gsub(' ','%20') | |
uri = URI("https://maps.googleapis.com/maps/api/place/textsearch/json?query=#{keyword}&name=goa&sensor=false&key=AIzaSyAGeap2PXa_AS19npQLjDlUbE8w0t_atwE") | |
response = Net::HTTP.get_response(uri) | |
result = JSON.parse(response.body) | |
#puts result.inspect | |
results_value=result["results"] | |
#puts results_value.inspect | |
similar_places=[] | |
results_value.each do |result| | |
similar_places.push("name"=>result["name"],"address"=>result["formatted_address"],"latitude"=>result["geometry"]["location"]["lat"],"longitude"=>result["geometry"]["location"]["lng"]) | |
end | |
return similar_places | |
end | |
similar_places = Findplaces("Taj") | |
puts similar_places.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment