Skip to content

Instantly share code, notes, and snippets.

@rajdeep26
Created May 6, 2013 20:28
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 rajdeep26/5527923 to your computer and use it in GitHub Desktop.
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.
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