当我创建 Gmap 时,她需要建立中心并缩放
一旦我们通过 GMap2 构造函数创建了一个地图,我们就需要对其进行初始化。这个初始化是使用地图的 setCenter () 方法完成的。setCenter () 方法需要 GLatLng 坐标和缩放级别,并且必须在对地图执行任何其他操作之前发送此方法,包括设置地图本身的任何其他属性。
由于这条路线不在中心位置 - 这是一个示例http://grab.by/4OD6
我应该根据坐标来获得中心吗?
并获得显示所有对象地图的缩放?
我的代码:
var TrainingGMap = Class.create ((
initialize: function (div_id, points, options) (
this.options = Object.extend ((), options)
this.points = points;
this.map = new GMap2 (document.getElementById (div_id));
this.map.setCenter (new GLatLng (this.points [0]. lan, this.points [0]. lon), 12);
this.map.setUIToDefault ();
this.set_route ();
)
set_route: function () (
var line = new Array ();
for (var i = 0; i <this.points.length; i + +) (
line [i] = new GLatLng (this.points [i]. lat, this.points [i]. lon);
)
var polyline = new GPolyline (line, "# aa0000", 5);
this.map.addOverlay (polyline);
)
));