Ruby on Rails ym4r_gm Google 地图

发布于 2024-10-17 17:03:26 字数 752 浏览 6 评论 0原文

我正在使用 ym4r_gm 在我的网站上创建标记地图。我创建了 1 个标记,适用于以下代码。

@map = GMap.new("locations_map")
@map.control_init(:large_map => true,:map_type => true)
geocode = GMap::Geocoding.get("G12 8BZ")
@map.record_init @map.add_overlay(GMarker.new([geocode.first.latitude,geocode.first.longitude], :title => "Hillhead, Glasgow", :info_window =>"Hillhead, Glasgow"))

我将如何让一组标记显示在地图上?我有一个邮政编码(邮政编码)数组,如下所示:

postcodes = ["G11 6PR", "G1 T3R", "G12 8BZ"]

我注意到 ym4r_gm 中的 MarkerGroup 类,但我无法弄清楚:-S

如果有人可以帮助我,那将是令人惊奇的,这里是文档的链接还。

http://ym4r.rubyforge.org/ym4r_gm-doc/

如有任何帮助,我们将不胜感激。

干杯

埃夫

I am using ym4r_gm to create a map of markers on my website. I have created 1 marker which is fine with the following code.

@map = GMap.new("locations_map")
@map.control_init(:large_map => true,:map_type => true)
geocode = GMap::Geocoding.get("G12 8BZ")
@map.record_init @map.add_overlay(GMarker.new([geocode.first.latitude,geocode.first.longitude], :title => "Hillhead, Glasgow", :info_window =>"Hillhead, Glasgow"))

How would I go about getting a group of markers to display on the map? I have an array of postcodes (zipcodes) like so:

postcodes = ["G11 6PR", "G1 T3R", "G12 8BZ"]

I have noticed the MarkerGroup class in ym4r_gm but I can not figure it out :-S

If you someone could give me a hand that would be amazing, here is a link to the docs also.

http://ym4r.rubyforge.org/ym4r_gm-doc/

Any help would be appreciated.

Cheers

Eef

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅忆 2024-10-24 17:03:26

不确定 ym4r_gm,但使用 ym4r_mapstraction 会是这样的(尽管 ym4r_gm 和 ym4r_mapstraction 都可用,因为我不认为 ym4r_mapstraction 有方便的地理编码助手)

 @map = Mapstraction.new("map_div", :google)         
 @map.control_init(:small_map => true, :map_type => true)

   postcodes.each do |this_postcode|
     begin
        # might want to put the Geocoding part into a begin-rescue clause
        # in case postcode isn't valid

        returned_geocode = GMap::Geocoding.get(this_postcode)
        this_title = this_postcode
        new_marker = Marker.new([returned_geocode.first.lat.to_f, returned_geocode.first.lon.to_f], :info_bubble => this_title, :icon => "images/gmaps/blue_image.png")
        blue_markers.push(new_marker)
      rescue Exception => e
        logger.error e.inspect
      end
   end
 @map.marker_group_global_init(MarkerGroup.new(blue_markers, true),"BLUE")

Not sure about ym4r_gm, but with ym4r_mapstraction it would be something like this (although this would be with both ym4r_gm and ym4r_mapstraction available since I dont think ym4r_mapstraction has the handy geocoding helper)

 @map = Mapstraction.new("map_div", :google)         
 @map.control_init(:small_map => true, :map_type => true)

   postcodes.each do |this_postcode|
     begin
        # might want to put the Geocoding part into a begin-rescue clause
        # in case postcode isn't valid

        returned_geocode = GMap::Geocoding.get(this_postcode)
        this_title = this_postcode
        new_marker = Marker.new([returned_geocode.first.lat.to_f, returned_geocode.first.lon.to_f], :info_bubble => this_title, :icon => "images/gmaps/blue_image.png")
        blue_markers.push(new_marker)
      rescue Exception => e
        logger.error e.inspect
      end
   end
 @map.marker_group_global_init(MarkerGroup.new(blue_markers, true),"BLUE")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文