Friday, October 9, 2009

How to integrate google maps with rails using ym4r _gm plugin

step 1:
first you need to install the plugin like this
 railsapp>
ruby script/plugin install svn://rubyforge.org/var/svn/ym4r/Plugins/GM/trunk/ym4r_gm
 
step 2:
put ym4r-gm.js file in javascripts directory(search in ym4r-gm plugin for js file)
step 3:
get googlemaps_api_key.yml file and put it in config folder(which consists of google maps api key)
step 4:
Mention like this in your controller which you want gmaps
require 'ym4r/google_maps/geocoding'
require 'rubygems'
require 'google_geocode' 
step 5:
In the view you need to mention like this otherwise it wont work:

<%= GMap.header %>
(application.rhtml)
 
<%= @map.to_html %>                                     
<%= @map.div(:width => 600,
:height => 400) %>(the view which u want)
 
step  6:
Mention like this in the method
@map = GMap.new("map_div")
@map.control_init(:large_map => true, :map_type => true)
@map.center_zoom_init([lat,lng], 13)