What is the best way to show location in Rails 4 app? - ruby-on-rails

I'm building an app for a client. The client want to be able to display street map with its location on the contact page.
I've never used maps in a web app before and I've been googling around.
there are so many options to use and I´m not sure which one to use.... this is just for displaying the streetmap, with a pin or something at the address, nothing too fancy.
should I use geokit-rails?
or rubygeocoder?
or Google Maps API?
or is there something else I can use?
what do you guys/girls recommend?
any suggestions would be great
thanks in advance
D

I use gem geocoder which I like. Just gem install geocoder. It supports geocoding and reverse geocoding, distance queries, rails 3-5. It is on github and website is here

Try gmaps4rails gem.
It is simple and easy to intregrate in rails application.
Check the Docs here.

Related

Google Geocoding API error: over query limit. - Rails

I know this question has been asked but most answers were a few years old and not all for a Ruby on Rails project. In my current project, I am using the Geocode gem (via Ruby on Rails) and anyone is able to search users by their location (which I also use the Carmen gem for country, subregion).
Anyway, I've been receiving this issue lately (Google Geocoding API error: over query limit.). After reading up on it, I see that this is quite common. Most of the resolutions seem to involve caching but others say that it does not work much/well.
I wanted to pose the question to many here and see what various people think is a good resolution. Ideally it would be great to keep the Geocoding gem within the project, but if it is not worth it, please let me know of an alternative. If you know of a resolution to this issue, please let me know too.
Thank you and simply looking to receive feedback for this situation =)
PS: I do not use the Google Maps API. The project is setup so that a user enters their information (using Carmen gem) and typing the cit. The location is geocoded and others can type in a city, state/region to find users within that region.
EDIT
Additional Question: When this limit is met, would that also cause the longitude and latitude value to be nil when a user signs up? Since it is as the limit, it will not geocode the location entered and so it keeps the value at nil? I've had this happen before so I just want to make sure this is why =P
EDIT 2 - ANSWER?
After speaking a bit (in comments below), it seems the best option is to cache the information. With that being said, after researching I see that there are a lot of legalities when it comes to caching with google? Again I do not use the Google Map API so the legal aspect may not be relevant?
Would this be a good solution to implementing the cache (https://github.com/codeforamerica/ohana-api/wiki/Customizing-the-geocoding-configuration)?
Just want to make sure I implement the cache aspect properly =P Thanks!
Joe
ANSWER
So after some research and help from japed (see comments above), I found this documentation (https://github.com/codeforamerica/ohana-api/wiki/Customizing-the-geocoding-configuration) which clearly explained how to setup Redis with Geocoding for caching purposes. It also provided another link with more information to test it in development before deploy.
Thank you!
Joe

Gmaps4Rails Google Map Interaction Nearest Location Feature Unfamiliar with Google Maps API

Currently I am building a rails application using the gmaps4rails gem. I have only been working on this for ten days,
http://greenearth.herokuapp.com/
I apologize I only have one dyne up so it may be quite slow on heroku.
I understand that the gem interacts with google js api v3 for me. Basicly I am making an rails application where I want to display trash bins locations on a google map. I have a table with an address as a column in the table, the gem allows me to take the address column and spit out markers on a map. I have to query all the address, translate them to json with a method provided by the gem (and its added to my model), then bring it out to my view. It will generate the required javascript.
I am quite tempted to switch to the geocoder gem because its a lot better documented. This gem just isn't well documented. I can't find questions on stackoverflow related to this gem.
My next step is to add a feature, where anybody can put in their most immediate address on a form and the map (google api) will calculate which of my trash bin location is nearest to this input address.
The gem's wiki is not well documented. I am not quite well versed with the google map api. In the mean time can someone point me to the correct tutorial? or the right direction?
After looking into it a bit more it seems the developer (apneadiving) is actually quite active, just not in the same place, see these guides on features: http://www.youtube.com/watch?v=Yg5-33zedqM
There is a second video as well.
Looking into it further I can't see a method in the documentation that calculates distance.
I recommend trying this tutorial:
http://briancray.com/posts/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api
Or just following the Distance Matrix service from Google.
I haven't tried to use these alongside the gem so you may have to change the code based on existing variables. It should* be easier because you have addresses and Lats/longs saved already.
Also have you set the App to initally geolocate the user?
I'm working on a similar issue myself so will update when I get there.
OK so after looking at the different gems I would recommend using both geocoder and gmaps4rails to achieve what you want. I would recommend gmaps4rails for the map rendering and marker addition and to use Geocoder for the distance calculations. Unfortunately neither gem is fully comprehensive in these features.
There is a good railscast on how to display nearby locations via a form using geocoder: http://www.youtube.com/watch?v=mUvGAcaW3bA
The method in geocoder is simply:
#address.nearbys(20)
Where '20' is a radius within which results will be displayed based on your other entries. Alternatively you could grab the user's current location using:
request.ip / request.location
Declare this as a variable then display nearby bins results in the show view (covered in rails cast). Just note that current location will not work in test/dev environment because of the webrick address as it says on the gem's homepage.
Hope that helps!

Google Maps V3 Geolocation Rails 3 gem 'geocoder' addresses not correct

I'm using Google Maps V3 and it's not only having trouble getting exact geolocations, it's sometimes not finding the correct city (even missing by more than 50 miles in some cases).
The way I'm using google maps is in my Rails 3 app with the gem 'geocoder'. I feel pretty sure it's not the geocoder gem that's causing google maps to be off, I think I've had this problem in google maps V3 before.
My question: is there a better experience for determining the user's location? Should I use the browser's built in geolocation features? Or should I be using a combination of Google Maps Geolocation and the browser's geolocation functions?
I imagined a scenario where I could ask the user if the town was correct, and if not they could enter their town, then store their town in the database, but it seems like a poor user experience. I hope to make this a app on mobile devices in the future, where it wouldn't be much of a problem, but for now it's a web app.
Anybody else have a good system for dealing with apps that rely on a user's location? Thanks!
I ran into the same problem with Geocoder. For me it appeared to not interpret the address correctly in certain cases. If I sent it '250w 450n' as the street address I would get back the coords for *formatted_address":"250 E 450 S,*. If I sent '250 w 450 n' I got back the exact location I was looking for. Try checking the json response you get back from Geocoder, it will tell you "partial_match":true,"types":["street_address"]}} if it "guessed" at something, and you can check the returned *formatted_address* to see what it came up with.
you can use their website as a quick check on what response you would get for a given address string.

Google Maps with Rails 3 multiple markers

I am trying to build a complex google maps application with Rails as the framework. I have seen the YM4R gem and others that supposedly help with google maps development, but I honestly just want to go without them for now.
How can I get it so that rails passes a huge list of points to my google maps view, and the google maps javascript plots all of the points? I understand I probably need to use json somewhere (such as render :json => #points), but when I place that in my controller, I get an Illegal Action error from WEBbrick.
Any help would be greatly appreciated. Thanks!
You should have a look at my gem:
https://github.com/apneadiving/Google-Maps-for-Rails
And for an example of an customization see Google Maps, Ruby on Rails, Zoom level with one marker

Integrating a google map into rails

Has anyone got any suggestions on where to start with building a google map into a rails app? I would like users to be able to add a marker by clicking the map, and have spent a few days looking for a suitable tutorial or plugin (beyond ym4r), to little avail...any help would be much appreciated as I am finding the Google Maps API rather difficult to get into! I've also come across the railskit for google maps - does anyone have any experience in using it?
Just fyi, I made https://rubygems.org/gems/gmaps4rails which is a useful wrapper with several options.
I probably wouldn't use YM4R. We tried it and found that it doesn't add much value because it just wraps the API. I would recommend working with Google Maps directly from JavaScript. Google Maps API documentation is pretty good, and there are quite a few examples on the web.
There is an example of a click handler on the map here, and adding a marker is just a matter of doing
map.addOverlay(new GMarker(latlng));

Resources