Search code examples
ruby-on-railsrubygoogle-mapsruby-on-rails-3.1gmaps4rails

gmaps4rails: HOW TO automatically add makers for locations matching a key word


I need to add markers for locations matching a specific keyword on my map. Such as "hotel" for instance.

I need to obtain the same result as when I search for that keyword on maps.google.com, only I want this search to be done automatically using gmaps4rails. I would add my location with a different marker on top.

cheers,

joel


Solution

  • the process would be:

    Ajax version

    1. you already have a map from gmaps4rails displayed

    2. submit a form remotely to your server

    3. create the proper query on your records in your controller, simply respond with .to_gmaps4rails

    4. use the js replaceMarkers function to clear the map and display the markers from the server response.

    5. use the geolocation functions of the client browser (beware, not available on all of them) + the js addMarkers function to display the user position.

    6. I wrote the relevant documentation here

    Standard version

    1. get the proper objects from your controller

    2. create the json from them

    3. create your map

    4. add a js callback to create the marker with user's position