开发者

anyone know how to change the size of a Google-Maps-for-Rails map

I have installed the sweet Google-Maps-for-Rails plugin, which seems to be under active development.

Right now, I am trying to figure out how to remove the google controls and change the size of the map. There is the start of go开发者_运维问答od documentation here, but I can't find how to do something this simple. I was able to go into the css file and change the width: of the div, but that is fragile and not the way I think the author intended.

the function loads:

window.onload = function() {Gmaps4Rails.map_options.auto_adjust = true;Gmaps4Rails.initialize();Gmaps4Rails.markers = [{"description": "", "title": "", "sidebar": "","longitude": "-77.0934", "latitude": "38.8115", "picture": "", "width": "", "height": ""} ];Gmaps4Rails.create_markers();}

so it seems to be a native option. any help greatly appreciated.


It is very easy to implement googlemaps even without using a plugin. basically all you need to do is include the gmaps javascript in the header:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

and an init function:

function initGmaps() {
var latlng = new google.maps.LatLng(48.839234,12.969335); // to be replaced with desired latitide / langitude
var myOptions = {
  zoom: 16,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  center: latlng
};
var myMap = new google.maps.Map(document.getElementById("gmaps"), myOptions);

var marker = new google.maps.Marker({
    position: latlng, 
    map: myMap, 
    title:"marker title"
});     

}

and you are done.

width and height would be specified by the css of the chosen div, in this example #gmaps.


from Gmaps4rails : Setting map width and height:

#gmaps4rails_map {
  width: 800px;
  height: 400px;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜