Reputation: 12623
So I know that google places API serves the place information (name, location, website, type ect) with JSON but I was wondering how to grab the data from the JSON?
Basically I've got a site where users can use the google maps API Ive set up to search for their retail shops and Id like to store all that information in a table so that way when you go to the user's profile page you can see their google place information on a integrated map.
Maybe theres an easier way to do that but Im not sure how.
Upvotes: 1
Views: 3934
Reputation: 101
For using Google Places API with Rails, you can use the Gem google_places:: https://github.com/marceldegraaf/google_places
I hope this will help you.
Upvotes: 1
Reputation: 79178
You should only use the google places api from the client. Google has a rate limit set pretty low, and it's based on IP address (at least for the google maps api). So if you're making too many requests from your web server, all of a sudden google cuts you off for the day. The way around this is to just do all the calls in javascript, so it's coming from the users IP address.
When the user types their address into your form, use the google places api to get the place id, or lat/lng coordinates, then save those along with everything else in your database. Then just use that data to fetch the place json from the google places api when they view the user profile.
Update
According to the google places docs, it's actually the "reference
token" you want to store, not the id
.
Since you want users to be able to search for their stores, you need to make 2 queries:
reference
token.Upvotes: 7
Reputation: 2118
I thought of doing the same with Geocoder, i think it's worth looking at.http://railscasts.com/episodes/273-geocoder?view=comments
Upvotes: 1