2011-01-15 70 views
1

谷歌地圖API,我需要一些幫助,顯示出3.0頁 我在堆棧溢出後 Google Maps API with Rails 3.0使用Rails 3.0

喜歡製圖我跟着從https://github.com/parolkar/cartographer說明我的軌道內的地圖。 另外我創建了一個cartographer.yml,並與谷歌鍵localhost的rails_app/config目錄下保存它:3000和本地主機: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 

和我有...

未定義的方法'名」爲:正常:符號

提取的源(左右線#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 %> 

謝謝...

回答

1

我從阿布舍克Parolkar得到這個和它的作品...

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> 
+0

請採取秒閱讀有關如何對常見問題解答使用代碼的標記。 – Will

+0

任何想法這裏發生了什麼http://stackoverflow.com/questions/12443178/cartographer-plugin-rendering-odd-map – Abram

2

同樣的問題在這裏。此快速修復是去以下文件:

供應商/插件/製圖/ lib中/ V3 /製圖/ 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

我並不想以後打破插件的圖標條款後來,所以不是刪除@ icon.name,而是將它放在一個開始,救援塊中。儘管如此。

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

要:

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

編輯:這已固定在最新修訂版:)一定要檢查的自述。


我已經在我的製圖師的叉修復了這個問題,並提交拉請求joshuamiller(作者)合併我的修正。

在此之前發生的,雖然,你可以作出這些修改來解決這個問題:

自述離開了,你還需要初始化的圖標。添加到您的控制器

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

然後用

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

取代gmarker.rb的第9行或者只是複製我的叉子

[email protected]:nicinabox/cartographer.git