我想通過從html.erb文件中的數組中獲得經度和緯度來在Google地圖上製作一系列標記,但我不知道如何發送經度和緯度並製作標記。如何在Google地圖上使用html地址製作標記數組?
var map;
var place1;
var defaultZoom = 16;
var mylat = '30.04441';
var mylng = '31.23571';
var centrePoint = new google.maps.LatLng(mylat, mylng);
var markerX;
//rendering the map
google.maps.event.addDomListener(window, 'load', loadMap);
// create map and add controls
function loadMap() {
//map options
var mapOptions = {
center: new google.maps.LatLng(30.0444196, 31.23571160000006),//center in cairo
zoom: defaultZoom,
mapTypeId: google.maps.MapTypeId.ROADMAP,
scaleControl : false,
scrollwheel : false,
draggable : true,
mapTypeControl : false,
panControl : false,
zoomControl : true,
zoomControlOptions: {
style : google.maps.ZoomControlStyle.LARGE,//zoom out and in at the map
position: google.maps.ControlPosition.LEFT_BOTTOM
}
};
//new map from google maps
map = new google.maps.Map(document.getElementById('google-map'),mapOptions);
}
and this is the html.erb
favorite_place is an object with attributes contains longitude and latitude in database
<h1>My Favorite Places</h1>
<% @favorite_places.each do |favorite_place| %>
<p><%=link_to truncate(favorite_place.name,length:19,omission:'',separator:','), controller: "favorite_places", action:"show",id:favorite_place.id %> </p>
<div id="google-map" class="map_new" ></div>
<%end%>
爲什麼不直接在javascript中寫ruby代碼? – Alex 2014-10-29 15:42:47
也回答你的問題,我們需要知道什麼是紅寶石代碼 – Alex 2014-10-29 15:43:29