Javascript 谷歌地图V3忽略中心值

Javascript 谷歌地图V3忽略中心值,javascript,jquery,google-maps-api-3,Javascript,Jquery,Google Maps Api 3,我创建了一个谷歌地图,上面有几个标记。其中一个标记与其他标记不同,我希望这个标记位于地图的中心。当我构建地图时,我将它的中心设置为与此标记相同的位置,但是它似乎被忽略了。这是我的密码: var map; // Global declaration of the map var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow var lat_longs = new

我创建了一个谷歌地图,上面有几个标记。其中一个标记与其他标记不同,我希望这个标记位于地图的中心。当我构建地图时,我将它的中心设置为与此标记相同的位置,但是它似乎被忽略了。这是我的密码:

var map; // Global declaration of the map
        var iw = new google.maps.InfoWindow(); // Global declaration of the infowindow
        var lat_longs = new Array();
        var markers = new Array();
        var markerCluster;
        function initialize() {

            centerlat = '53.1957381200000';
            centerlong = '-2.8940324870000';

            if(centerlat=='FALSE' && centerlong=='FALSE') {
                var myLatlng = new google.maps.LatLng(51.4734,-0.137329);
            } else {
                var myLatlng = new google.maps.LatLng(53.1957381200000,-2.8940324870000);
            }
            var myOptions = {
                //zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);



            var myLatlng = new google.maps.LatLng(52.6274684, -1.1290035);

            var markerOptions = {
                map: map,
                position: myLatlng,
                title: "Head Office"        
            };
            marker_0 = createMarker(markerOptions);

            marker_0.set("content", '<h4>Head Office</h4><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis urna nibh, sed venenatis felis. In hac habitasse platea dictumst. Sed suscipit lobortis luctus. Quisque vestibulum facilisis risus, in suscipit nisl hendrerit et.</p><p><a href="#contact_form" class="btn btn-primary contact-office" data-office_id="13">Contact This Office</a></p>');

            google.maps.event.addListener(marker_0, "click", function(event) {
                iw.setContent(this.get("content"));
                iw.open(map, this);

            });



            var myLatlng = new google.maps.LatLng(51.489827, -0.196938);

            var markerOptions = {
                map: map,
                position: myLatlng,
                title: "London"     
            };
            marker_1 = createMarker(markerOptions);

            marker_1.set("content", '<h4>London</h4><p>Our London office is based at the Earls Court Exhibition centre. Our central location allows us to offer our award winning services to all venues across the capital.</p><p><a href="#contact_form" class="btn btn-primary contact-office" data-office_id="12">Contact This Office</a></p>');

            google.maps.event.addListener(marker_1, "click", function(event) {
                iw.setContent(this.get("content"));
                iw.open(map, this);

            });



        /* IF the user has performed a search then add a marker showing the center of the search */
        if(centerlat!=='FALSE' && centerlong!=='FALSE') 
        {
            var myLatlng = new google.maps.LatLng(centerlat, centerlong);

            var markerOptions = {
                map: map,
                position: myLatlng,
                title: "Your Location",
                icon : "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"
            };
            marker_you = createMarker(markerOptions);

            marker_you.set("content", '<h4>Your Location</h4><p>This is the approximate location of your search</p>');

            google.maps.event.addListener(marker_you, "click", function(event) {
                iw.setContent(this.get("content"));
                iw.open(map, this);

            });
        }


        var clusterOptions = {
            gridSize: 60,
            minimumClusterSize: 5
        };
        markerCluster = new MarkerClusterer(map, markers, clusterOptions);

        fitMapToBounds();


        }


    function createMarker(markerOptions) {
        var marker = new google.maps.Marker(markerOptions);
        markers.push(marker);
        lat_longs.push(marker.getPosition());
        return marker;
    }

    function fitMapToBounds() {
        var bounds = new google.maps.LatLngBounds();
        if (lat_longs.length>0) {
            for (var i=0; i<lat_longs.length; i++) {bounds.extend(lat_longs[i]);}
            map.fitBounds(bounds);
        }
    }

    window.onload = initialize;
var映射;//全球地图宣言
var iw=new google.maps.InfoWindow();//信息窗口的全局声明
var lat_longs=新数组();
var markers=新数组();
var-markerCluster;
函数初始化(){
centerlat='53.19573812000000';
centerlong='-2.8940324870000';
如果(centerlat=='FALSE'和¢erlong=='FALSE'){
var mylatng=new google.maps.LatLng(51.4734,-0.137329);
}否则{
var mylatng=new google.maps.LatLng(53.19573812000000,-2.8940324870000);
}
变量myOptions={
//缩放:13,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
var mylatng=newgoogle.maps.LatLng(52.6274684,-1.1290035);
变量标记选项={
地图:地图,
职位:myLatlng,
标题:“总部”
};
marker_0=创建标记(markerOptions);
marker_0.set(“内容”,总部Lorem ipsum Door sit amet,尊敬的精英。Quisque quis urna nibh,sed venenatis felis。在hac hac Habitase platea dictumst.sed suscipit lobortis luctus.Quisque venenatis facilisis risus,suscipit nisl hendrerit et.

); google.maps.event.addListener(标记0,“单击”,函数(事件){ setContent(this.get(“content”); iw.打开(地图,本); }); var mylatng=new google.maps.LatLng(51.489827,-0.196938); 变量标记选项={ 地图:地图, 职位:myLatlng, 标题:“伦敦” }; marker_1=创建标记(markerOptions); marker_1.set(“content”,伦敦我们在伦敦的办事处设在Earls Court展览中心。我们的中心位置使我们能够向首都的所有场馆提供屡获殊荣的服务。

>); google.maps.event.addListener(标记1,“单击”,函数(事件){ setContent(this.get(“content”); iw.打开(地图,本); }); /*如果用户已执行搜索,则添加显示搜索中心的标记*/ if(centerlat!='FALSE'&¢erlong!='FALSE') { var mylatng=new google.maps.LatLng(centerlat,centerlong); 变量标记选项={ 地图:地图, 职位:myLatlng, 标题:“你的位置”, 图标:“http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png" }; marker\u you=createMarker(markerOptions); marker_you.set(“content”,“Your Location这是您搜索的大致位置”

); google.maps.event.addListener(标记“单击”,函数(事件){ setContent(this.get(“content”); iw.打开(地图,本); }); } 变量clusterOptions={ 网格大小:60, 最小群集大小:5 }; markerCluster=新的MarkerClusterer(地图、标记、聚类选项); fitMapToBounds(); } 函数createMarker(markerOptions){ var marker=新的google.maps.marker(markerOptions); 标记器。推(标记器); lat_longs.push(marker.getPosition()); 返回标记; } 函数fitMapToBounds(){ var bounds=new google.maps.LatLngBounds(); 如果(横向长度>0){
对于(var i=0;iHi,需要更好地定义您确切想要发生的事情以及当前正在发生的事情。此外,请确保您已删除internet文件并进行了完全刷新,以确保您的测试页面上有最新的脚本文件和css。不要忽略它,您可以在
fitMapToBounds()中更改映射的边界
,更改边界也会更改中心。我没有使用
fitMapToBounds()
,但有相同的问题。如果没有标记,地图中心将正确。