Ruby & Google Places API: Empty fields
I'm trying to use the Google Places API (here) in a ruby on rails app. I'm using a gem called google_places
(here). As far as I know the gem simply allows an easy interface to send the required HTTP requests and parse the JSON output into ruby hashes. I'm using the following code in my controller:
@client = 开发者_如何学JAVAGooglePlaces::Client.new("(my api key)")
@spotList = @client.spots(-100, 73.1957362, :radius => "5000")
And in the view, I use the following to display the places:
<% @spotList.each do |x| %>
<%= x.name %> <br/>
<% end %>
Now that works just fine, but if I replace x.name
with x.formatted_address
or x.address_components
, I just get a blank page. I tried printing these fields in the log too, and I just a blank line of output. I've tried a lot of different latitudes and longitudes, and I'm getting names of banks with the current ones, which should have addresses.
I don't understand what's going on. I think I'm using the Google Places API incorrectly, since the google_places
returns some other fields correctly. Can anyone please shed some light on what might be going on?
I just worked on this,
parse through @spotList and take out the reference of each place returned in response. Now, @client.spot "reference" will give you the data which contains the x.formatted_address or x.address_components.
精彩评论