根据标记中心Google Map

时间:2017-11-26 21:31:12

标签: javascript google-maps google-maps-api-3 google-maps-markers centering

我想基于动态加载的标记来引导Google Map。现在我在地图上显示两个标记(参见script.js文件):

$mapster.mapster('addMarker', {
  location: 'Golden Gate Bridge, San Francisco, CA',
  content: 'Example text 2'
});

$mapster.mapster('addMarker', {
  lat: 37.751350,
  lng: -122.485833,
  content: '<div style="color: #f00;">Example text 1</div>'
});

一切正常,因为我定义了地图居中的坐标(参见map-options.js文件):

mapster.MAP_OPTIONS = {
  center: {
    lat: 37.791350,
    lng: -122.435883
  },
  zoom: 10,
  disableDefaultUI: false,
  scrollwheel: true,
  draggable: true,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  zoomControlOptions: {
    position: google.maps.ControlPosition.LEFT_BOTTOM,
    style: google.maps.ZoomControlStyle.DEFAULT
  },
  panControlOptions: {
    position: google.maps.ControlPosition.LEFT_BOTTOM
  },
  cluster: {
    options: {
      styles: [{
        url: 'https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclusterer/images/m2.png',
        height: 56,
        width: 55
        //textColor: '#000'
        //textSize: 12
      }, {
        url: 'https://raw.githubusercontent.com/googlemaps/v3-utility-library/master/markerclusterer/images/m1.png',
        height: 56,
        width: 55
        //textColor: '#000'
        //textSize: 12
      }]
    }
  },
  geocoder: true
};

我如何根据任何加载的标记来居中我的Google地图?我基本上想要实现这样的目标: Center a Google Map based on Markers

这是我的代码: https://plnkr.co/edit/sduZKBXIIijhnkCIpSoR?p=preview

0 个答案:

没有答案