0

我想通过从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%> 
+0

为什么不直接在javascript中写ruby代码? – Alex 2014-10-29 15:42:47

+0

也回答你的问题,我们需要知道什么是红宝石代码 – Alex 2014-10-29 15:43:29

回答

0

您可以使用此代码的显示标记在地图上

Marker marker=map.add(new MarkerOptions().position(new LatLng(Lat1,Lng1)).title("Place_name")); 

这里的地图是一个GoogleMap对象和LAT1和Lng1应分别要显示的地方的经度和纬度。

+0

我知道如何把一个单一的标记与lng和lat从变量在javascript中,但我想有一个数组在html.erb从favorite_places和把它发送到javascript和制作一个标记数组@RahulSolanki – 2014-10-26 16:43:21

+0

@Korem我知道如何把一个标记与lng和纬度从变量在javascript中,但我想从一个数组在html.erb从favorite_places发送到javascript并制作一组标记 – 2014-10-26 17:30:41

相关问题