YM4R multiple points on Google Map

Just started using YM4R to display a Google Map. I can display a map with 1 Marker. But, I’d like to initialize the map with multiple markers. Does anyone know how to do that?

I’ve tried:

def index

@map = GMap.new("map_div")
@map.control_init(:large_map => true,:map_type => true)
@map.center_zoom_init([47.2700000, -122.311880],15)
@map.overlay_init(GMarker.new([47.2700000

, -122.311880],:title => “Hello”, :info_window => “Info! Info!”)) @map.add_overlay(GMarker.new([47.2700000, -122.311800],:title => “M2”, :info_window => “Marker 2”))

end

The .add_overlay(…) doesn’t display.

Also, Does anyone know how to get the GPS coordinates for a street address?

Can't you just feed in an array of markers?

@markers.each do |marker_seq|            @map.overlay_init(marker_seq) end

Thanks, that worked, (once I moved the coordinated far enough apart that both markers would display). -Larry

Can’t you just feed in an array of markers?

@markers.each do |marker_seq| @map.overlay_init(marker_seq) end

This haven’t figured out how to get the longitude, latitude for a given US address. Should I put that question in a separate post?

-Larry

Found the answer to the coordinate problem. Way at the bottom of the readme, it mentions in passing that GMarker now accepts strings as well as coordinates. So all I have to do is:

@address = GMarker.new(“some address that Google can find”)

Very cool!

There is also a Geocode::Get method that queries Google and returns coordinate info. Haven’t played with it yet. -Larry

Hunter Hillegas wrote:

Can't you just feed in an array of markers?

@markers.each do |marker_seq|            @map.overlay_init(marker_seq) end

Hi Hunter

I have a similar problema with YM4R

My map only display the last point, this is my code:

     @map = GMap.new("map_div_id")      @map.control_init(:large_map => true, :map_type => true)      @map.center_zoom_init([40.41,-3.70], 4)

     markers = Array.new()

     for lab in @laboratories do          html = gethtmlmap(lab)          c1, c2 = lab.coords.split(",")

          markers << GMarker.new([c1.to_i,c2.to_i],          :title => lab.name, :info_window => html)

     end

     markers.each do |marker_seq|            @map.overlay_init(marker_seq)      end

Could you help me please?

Thanks in advance

Just a quick link to some example code that may help you:

http://github.com/kete/kete/blob/master/app/views/search/_results.rhtml # lines 43 - 63ish

Pay particular attention to lines 61 and 62.

Hope that helps, Walter

Walter McGinnis wrote:

Just a quick link to some example code that may help you:

http://github.com/kete/kete/blob/master/app/views/search/_results.rhtml # lines 43 - 63ish

Pay particular attention to lines 61 and 62.

Hope that helps, Walter

Hi Walter, thanks for your reply

My original code were like this post, with it, only show the last result of my query, like this:

     @map = GMap.new("map_div_id")      @map.control_init(:large_map => true, :map_type => true)      @map.center_zoom_init([40.41,-3.70], 4)

     for lab in @laboratories do          html = gethtmlmap(lab)          c1, c2 = lab.coords.split(",")

          marker = GMarker.new([c1.to_i,c2.to_i],          :title => lab.name, :info_window => html)           @map.overlay_init(marker)      end

I don't know what is wrong.

Thanks!

Hmm, I don't see an obvious cause for the problem. I would chuck in a debug on @map and perhaps marker objects to see what they look like.

One difference that my code has (in the controller where @map object is initialized) is that it uses this:

@map.center_zoom_on_points_init(*@coordinates_for_results)

I would say that implies that it can handle multiple markers, but if it is what turns on support for multiple markers it's pretty unexpected.

Hope this helps, Walter

This indeed is the source of your problem I think. You code centers on one specific point with a zoom level of 4. If your markers don't fall within the map's area as centered around this point at this zoom level, they appear to not exist. However, they are simply not visible.

To test my theory, simply try zooming out and see if the other markers appear.

With multiple markers you almost certainly want to use the center_zoom_on_points_init method to get a map that will show all points. There is a decent walk through of the process here:

http://www.codequest.eu/articles/google-maps-rails-and-solr-spatial-search

Cheers, Walter

Walter McGinnis wrote: