Skip to content

Instantly share code, notes, and snippets.

@rajdeep26
Created May 6, 2013 20:26
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/5527906 to your computer and use it in GitHub Desktop.
Save rajdeep26/5527906 to your computer and use it in GitHub Desktop.
This Ruby code gives suggestions for autocomplete of places for the given keyword. The suggestions are fetched from the Google Maps using Google Maps Auto-complete API.
require "net/http"
require "json"
def autocomplete(keyword)
keyword=keyword.gsub(' ','%20')
uri = URI("https://maps.googleapis.com/maps/api/place/autocomplete/json?input=#{keyword}+in+india&types=establishment&sensor=false&key=AIzaSyAGeap2PXa_AS19npQLjDlUbE8w0t_atwE")
response = Net::HTTP.get_response(uri)
result = JSON.parse(response.body)
# puts result
descriptions = result["predictions"]
descriptions.each do |description|
puts description["description"]
end
end
autocomplete("taj")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment