API Карт Google с Rails 3.0 - PullRequest
       3

API Карт Google с Rails 3.0

1 голос
/ 15 января 2011

Мне нужна помощь, показывая карту внутри моих рельсов 3.0 страницы Я увлекаюсь картографом в стеке переполнения поста API Карт Google с Rails 3.0

Я следовал инструкциям https://github.com/parolkar/cartographer. Кроме того, я создал cartographer.yml и сохранил его в каталоге rails_app / config с ключами Google для localhost: 3000 и localhost: 3000 / gmap /

мой контроллер выглядит так:

 def show
    @place = Place.find(params[:id])

    @map = Cartographer::Gmap.new( 'map' )
    @map.zoom = :bound
    marker1 = Cartographer::Gmarker.new(:name=> "taj_mahal", :marker_type => "Building",
              :position => [27.173006,78.042086],
              :info_window_url => "/url_for_info_content")
    marker2 = Cartographer::Gmarker.new(:name=> "raj_bhawan", :marker_type => "Building",
              :position => [28.614309,77.201353],
              :info_window_url => "/url_for_info_content")

    @map.markers << marker1
    @map.markers << marker2


    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @place }
    end
  end

и я получил ...

неопределенное имя метода для: normal: Symbol

Извлеченный источник (около строки # 44):

41: </p>
42: 
43: <%= raw Cartographer::Header.new.to_s %>
44: <%= raw @map.to_html %>
45: 
46: <%= link_to 'Edit', edit_place_path(@place) %> |
47: <%= link_to 'Back', places_path %>

Спасибо ...

Ответы [ 4 ]

2 голосов
/ 16 января 2011

Та же проблема здесь.Чтобы исправить это, перейдите к следующему файлу:

vendor / plugins / cartographer / lib / v3 / cartographer / gmarker.rb, строка 57 и

измените его с:

script << "#{@name} = new google.maps.Marker({map: null,position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: true, icon: #{@icon.name}}); \n"

до:

script << "#{@name} = new google.maps.Marker({map: null,position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: true}); \n"

Значок отсутствует, но карта отобразится.Это будет работать по крайней мере, пока они не решат проблему.

Также, в качестве плюса, не забудьте указать некоторое измерение для div карты, иначе оно не будет отображаться :).

.map {
  border: black 0.5px solid;
  width: 400px;
  height: 400px;
}

Прямо сейчас для меня это работает.

1 голос
/ 05 февраля 2011

РЕДАКТИРОВАТЬ: Это было исправлено в последней ревизии :) Обязательно проверьте readme.


Я исправил эту проблему в своем форке Cartographer и отправил запрос на извлечение joshuamiller(автор), чтобы объединить мои исправления.

Прежде чем это произойдет, вы можете внести следующие исправления, чтобы решить эту проблему:

В README не требуется инициализация значков.Добавьте это к вашему контроллеру

@map.icons << Cartographer::Gicon.new

Затем замените строку 9 файла gmarker.rb на

@icon = options[:icon] || Cartographer::Gicon.new

Или просто клонируйте мою вилку

git@github.com:nicinabox/cartographer.git
1 голос
/ 27 января 2011

Я не хочу разбивать плагин на более поздние версии с точки зрения пиктограмм позже, поэтому вместо удаления @ icon.name я просто поместил его в начало, спасательный блок ... хотя большой улов.1002 *

Кому:

begin
  script << "#{@name} = new google.maps.Marker({map: null,position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: #{@draggable}, icon: #{@icon.name}}); \n"
rescue
  script << "#{@name} = new google.maps.Marker({map: null,position: new google.maps.LatLng(#{@position[0]}, #{@position[1]}), draggable: #{@draggable}}); \n"
end
1 голос
/ 17 января 2011

Я получил это от Абхишека Паролкара, и это работает ...

class WelcomeController < ApplicationController
  def index
    @map = initialize_map()
    @map.zoom = :bound
    @icon_org = Cartographer::Gicon.new(:name => "org",
          :image_url => '/images/org_icon.gif',
          :shadow_url => '/images/org_icon.gif',
          :width => 32,
          :height => 23,
          :shadow_width => 32,
          :shadow_height => 23,
          :anchor_x => 0,
          :anchor_y => 20,
          :info_anchor_x => 5,
          :info_anchor_x => 1)
    # Add the icons to map
    @map.icons <<  @icon_org
    @marker1 = Cartographer::Gmarker.new(:name=> "org11", :marker_type => "Organization",
              :position => [27.173006,78.042086],
              :info_window_url => "/welcome/sample_ajax",
              :icon => @icon_org) 
    @marker2 = Cartographer::Gmarker.new(:name=> "org12", :marker_type => "Organization",
              :position => [13.031332, -24.09375],
              :info_window_url => "/welcome/sample_ajax",
              :icon => @icon_org)          

    @map.markers << @marker1
    @map.markers << @marker2

  end
  def test

  end
  def sample_ajax
    render :text => "Success"
  end
  private
  def initialize_map
     @map = Cartographer::Gmap.new( 'map' )    
     @map.controls << :type
     @map.controls << :large
     @map.controls << :scale
     @map.controls << :overview
     @map.debug = false 
     @map.marker_mgr = false
     @map.marker_clusterer = true

     cluster_icons = []


     org = Cartographer::ClusterIcon.new({:marker_type => "Organization"})
      org << {
                  :url => '/images/drop.gif',
                  :height => 73,
                   :width => 118,
                  :opt_anchor => [10, 0],
                  :opt_textColor => 'black'
                }
         #push second variant
      org << {
                  :url => '/images/drop.gif',
                  :height => 73,
                  :width => 118,
                  :opt_anchor => [20, 0],
                  :opt_textColor => 'black'
                }

        #push third variant
       org << {
                  :url => '/images/drop.gif',
                  :height => 73,
                  :width => 118,
                  :opt_anchor => [26, 0],
                  :opt_textColor => 'black'
              }
      cluster_icons << org



      @map.marker_clusterer_icons = cluster_icons



     return @map
   end

end

и в представлении

<%= raw Cartographer::Header.new.to_s %>
<%= raw @map.to_html %>

<div style="width:600px;height:400px;" id="map" > [Map]</div> 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...