Created
May 6, 2013 20:26
-
-
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.
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 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