如何使用jquery.gmap.js将google map v3居中

如何使用jquery.gmap.js将google map v3居中,jquery,google-maps,google-maps-api-3,center,Jquery,Google Maps,Google Maps Api 3,Center,如何使用jquery.gmap.js()将google map v3居中(视点)。 我在同一个城市有两个或多个标记,但我希望将地图居中于地图上的特定点(或将坐标居中于第一个标记)。 我的jquery是: $(document).ready(function() { $('#map_canvas').gMap({ zoom: 16, markers:[ { latitude: 51.51793,

如何使用jquery.gmap.js()将google map v3居中(视点)。 我在同一个城市有两个或多个标记,但我希望将地图居中于地图上的特定点(或将坐标居中于第一个标记)。 我的jquery是:

$(document).ready(function()
{  
 $('#map_canvas').gMap({            
    zoom: 16,
    markers:[
        {
            latitude: 51.51793,
            longitude: -0.140419,
            html: 'some_text_1',
            popup: true,                    
        },
        {
            latitude: 51.52028,
            longitude: -0.122766,
            html: 'some_text_2',
            popup: true,    
        }
    ]
});

}))

您可以通过调用
.gMap({…})


您需要将“popup”的值设置为false,否则gmap将使第二个标记居中。下面是更新的js代码

$(document).ready(function () {
    $('#map_canvas').gMap({
        zoom: 16,
        markers: [{
            latitude: 51.51793,
            longitude: -0.140419,
            html: 'some_text_1',
            popup: false,
        }, {
            latitude: 51.52028,
            longitude: -0.122766,
            html: 'some_text_2',
            popup: true,
        }]
    });

    $('#map_canvas').gMap('centerAt', {
             latitude: 51.51793,
            longitude: -0.140419,
            zoom: 16
        });
});

这是小提琴…

就是这样,对吗?“$(document).ready(function(){$('#map_canvas')).gMap({…});$('#map_canvas').trigger('gMap.centerAt',[51.51793,-0.140419]);”谢谢,如果我还有一个或两个标记,并且我需要“popup:true”将最后一个标记居中,对吗?
$(document).ready(function () {
    $('#map_canvas').gMap({
        zoom: 16,
        markers: [{
            latitude: 51.51793,
            longitude: -0.140419,
            html: 'some_text_1',
            popup: false,
        }, {
            latitude: 51.52028,
            longitude: -0.122766,
            html: 'some_text_2',
            popup: true,
        }]
    });

    $('#map_canvas').gMap('centerAt', {
             latitude: 51.51793,
            longitude: -0.140419,
            zoom: 16
        });
});