Generating Google Maps markers using Ruby - ruby-on-rails

I would like to do a very simple task: add some markers in a Google Map using a list of addresses from an array.
I have been thinking about generating the Google Maps JavaScript API code using ruby (printf) but this does not seem like a very clean and beautiful solution...
I have read about YM4R for Ruby on Rails... my project is pretty simple and I have never worked with Ruby on Rails... I have also never used JQuery... but I am very willing to learn to use this tools :)
What do you think will be the best approach to generating the markers?

Fyi, I've just released a new version of gmaps4rails.
It's based on Rails 3 and uses Google maps API V3:
https://github.com/apneadiving/Google-Maps-for-Rails

YM4R is a good choice. In the end you'll just need a few lines of code to get this done, as outlined in the tutorial. Even given your background, you should be able to follow the examples and get things working.
We also use the Geokit plugin, which is a little more complicated because of the set-up. But if you already have the lat/lon, you're good.

Related

Buying domain using API

I've been googling for more than 2 weeks to find any Rails code working with OpenSRS API, but I couldn't find any good solution at all.
Could anyone give me some example or references of using OpenSRS API with Rails 3?
After some quick browsing on the OpenSRS site, I found this gem. start here, definitely:
https://github.com/voxxit/opensrs
If you want to write it all yourself, the ruby toolkit is on this page: http://www.opensrs.com/site/resources/documentation/api#api
But really, the opensrs gem looks like it's all you'll need.

Neo4j spatial in ruby

I recently started playing with neo4j graph database in a Rails application and loved how rich the neo4j is. Although I saw that there is spatial support for neo4j via neo4j-spatial I haven't seen an example in a ruby application to get me started (using the ruby port of neo4j-spatial).
What I want to accomplish at first is to have a User model and a Poi model both having lat, lng attributes and make a query: Show me the Poi's that are at most 10km away from me
but I have no idea how I have to go about using the ruby gem. All I have found on the subject is this blog spot.
Does anyone know how am I supposed to do this in ruby? Thanks!
I think the ruby gem is a bit out of date. I suggest either forking and updating it, or use straight Java APIs for that, see the original java methods that the Spatial ruby just wraps.
Lemme know if you want to contribute and update, would be great!
I wrote the gem as a simple wrapper. It depends on neo4j.rb so you get all the necessary ruby on rails capabilities from that. Then it includes the spatial dependencies also. In addition it provides utilities for wrapping OSM import and export and dynamic layer support. It does not provide utilities to wrap the simple point layer which you seem to want. However you kind of get that for free anyway with jruby directly wrapping all of the java API for you.
My recommendation would be to use neo4j-spatial.rb and then use the neo4j.rb capabilities to build your model. Access the simple point layer directly from jruby and just add your new nodes to that. Then you can call the distance search function, also from jruby.

trying to build simple web app with Google Maps API

I'm trying to build a simple web app using the Google Map API. I haven't decided if I want to use Rails or Django yet. I've been looking for some tutorials, but none have given me really what I'm looking for. Understand, I'm a newbie when it comes to both Rails and Django.
What I want to do is like this:
http://durasupreme.com/dealer-locator
Where you type in a zip code and it returns a map with pins for the locations on a map. I already have the database information, I'm just wondering what the best way to do this. I feel like I have the idea, I know the tools I need to use, but I don't know how to put it all together.
Any help or links to resources would be greatly appreciated.
D
Here are a few useful links if you decide to go for Rails:
Geocoder
Railscast about Geocoder
Google Maps for Rails
What you are trying to do doesn't have much to do with Django or Rails. It will be mostly javascript. Here's a simple implementation outline:
Follow the tutorials to get started on google maps api on a static local html file.
In javascript write a map_init and add_marker helper functions.
When confident, add the link, div, and script tags you wrote to your template.
Have your view/controller method get a list of objects from the db.
Pass them to the template
In the template do a for loop over the object list.
inside the loop use the appropriate obj attributes to feed the add_marker helper function.

What is the best way to implement a "Find a Store" feature in Rails?

I will be implementing a search feature on a project to allow a user to find the nearest store based on driving time given a input physical address. I would prefer showing a Google maps of the closest dealers. I am using PostgreSQL 8.4.x with Rails 2.1. Can anyone recommend a good solution (Ruby gem, Maps API such Google, PostGIS database, etc)? Thanks, Chirag
I generally use Geokit:
https://github.com/andre/geokit-gem
Or Geokit Rails 3:
https://github.com/jlecour/geokit-rails3
Then of course, I use my gem gmaps4rails
Haven't really done anything like that before, but these resources should be quite useful :
http://ym4r.rubyforge.org/tutorial_ym4r_georuby.html
https://github.com/apneadiving/Google-Maps-for-Rails

Ruby on rails gem for google map integration

I would like to ask which is the best solution for integrating google maps into ruby on rails apps. Is a specific gem worth it or should we write our own views for it?
Thanks for any input.
Fyi, I've finished a stable release of gmaps4rails.
See: https://github.com/apneadiving/Google-Maps-for-Rails
If your requirements are only to show google map of specific region, possibly with some markers, you can use Google Maps Static Image API, for example:
<img src="http://maps.google.com/maps/api/staticmap?size=255x255&maptype=roadmap&sensor=false&markers=color:blue|label:A|Chicago,IL&markers=color:purple|label:B|Hammond,IN" alt="Static, Marked Map of Chicago, Illinois and Hammond, Indiana with no Center and Zoom"></img>
The result is:
Here is a good article on subject. Also it's possible to specify geo location with latitude and longitude on markers:
markers=color:pink|label:A|55.783041, -137.500994
So in Rails you can use, for example, image_tag with google map image path helper:
= image_tag google_map_image_path, :alt => "Google Map"
I've used the YM4R, Georuby and spatial adapter gems with good results before.
see this description.
As of November 2012,the best gem for google map integration which I have found is geocoderIt provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), distance queries for ActiveRecord and Mongoid, result caching, and more. Designed for Rails but works with Sinatra and other Rack frameworks too.
You can get a railscasts too.
GoogleMaps gem is a nice one. It adds all basic JS scripts but a full-functional dynamic map can't be done without JS coding anyway.
There are also JS plugins, the most attractive of them are gmap3, Maplace.Js and gmaps.js.
Gems and plugins allow saving time on basic things but using them imposes some restrictions. For example, if Google makes changes in its Maps API, you have to wait for an updated version of the gem or plugin or integrate manually.
In fact, there is no major difficulty in integrating Google Maps into Rails app and IMHO it makes sence to do it without gems.
See this article for a detailed walkthrough on integrating Google Maps into ruby on rails apps: How to Integrate Google Maps into Ruby on Rails App.
As of December 2021, I recommend this method https://www.driftingruby.com/episodes/google-maps-api-with-stimulusjs that uses Stimulus.js
A few bits must be updated for Rails 7.
You don't need to do rails webpacker:install:stimulus, its already included via Hotwire
rename turbolinks to turbo
packs/application.js no longer exists, I have yet to find the best location for this. for now I put it in app/javascripts/controllers/index.js
import { Controller} from "stimulus" has become import { Controller } from "#hotwired/stimulus"
That's it

Resources