「你正在做不支持‘看’的變量變化的javascript_tag辦法......」
是的,真正的,甚至當我點擊我的周圍應用和重新加載頁面時, javascript_tag中的值保持不變。這就像我的應用程序啓動時我的js文件加載一樣,@user的經度和緯度值保持不變,即使它們應該改變,並且地圖總是以相同的座標繪製。
'Gon'寶石也不適合我。非常少的文檔,特別是像我這樣的新手。
什麼成功:要生成
在哪裏,我想在地圖的頁面,show.html.erb:
<!-- This is here, to generate the user's latitude and longitude dynamically -->
<!-- The data-lat and lng attributes are used in 'initialise_google_maps' function, in scripts.js' -->
<div id="user-position" class="hidden" data-lat="<%= @user.lat %>" data-lng="<%= @user.lng %>"></div>
然後在我的scripts.js中:
function initialize_google_maps() {
var user_longitude = $("#user-position").attr("data-lng");
var user_latitude = $("#user-position").attr("data-lat");
var currentlatlng = new google.maps.LatLng(user_latitude, user_longitude);
var zoom = 10;
var myOptions = {
zoom: zoom,
center: currentlatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP, // ROADMAP, SATELLITE, HYBRID
streetViewControl: false
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({map: map, position: currentlatlng, icon:{oppacity:0}});
var circle = new google.maps.Circle({
map: map,
fillOpacity: 0,
strokeWeight: 2,
strokeOpacity: 0.7,
radius: 10000,
});
circle.bindTo('center', marker, 'position');
}
現在工作。
乾杯克里斯,我會看看Gon。問題也看起來更好。 – CHarris 2013-05-09 08:19:12