Question

J'utilise ym4r_gm pour créer une carte des marqueurs sur mon site Web. J'ai créé 1 marqueur, ce qui est bien avec le code suivant.

@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"))

Comment pourrais-je faire afficher un groupe de marqueurs sur la carte? J'ai un tableau de codes postaux (codes postaux) comme ainsi:

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

J'ai remarqué la classe MarkerGroup dans ym4r_gm mais je ne peux pas le comprendre: -s

Si quelqu'un pouvait me donner une main qui serait incroyable, voici également un lien vers les documents.

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

Toute aide serait appréciée.

Acclamations

Eef

Était-ce utile?

La solution

Je ne suis pas sûr de ym4r_gm, mais avec ym4r_mapstraction, ce serait quelque chose comme ça (bien que ce soit avec ym4r_gm et ym4r_mapstraction disponible car je ne pense pas que YM4R_MAPSTRACTION ait le 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")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top