缩放级别 - Google地图,国家/地区

时间:2017-07-10 13:37:44

标签: java google-maps

如果您查看此页面:https://banting.co.za/find-a-coach/

你会看到世界地图几乎与自身重复,但它是一个插件 有什么简单的我想让世界地图适合而不重复吗?

/ ** *所有位置都映射脚本 * / jQuery的(函数($){

$(document).ready(function(){
    loadmap();
});

function loadmap()
{
    var locations = wpsl_locator_all.locations;
    var mapstyles = wpsl_locator.mapstyles; 
    var mappin = ( wpsl_locator.mappin ) ? wpsl_locator.mappin : '';
    var bounds = new google.maps.LatLngBounds();

    var mapOptions = {
            mapTypeId: 'roadmap',
            mapTypeControl: false,
            zoom: 8,
            styles: mapstyles,
            panControl : false
        }
    if ( wpsl_locator.custom_map_options === '1' )  mapOptions = wpsl_locator.map_options;

    var infoWindow = new google.maps.InfoWindow(), marker, i;
    var map = new google.maps.Map( document.getElementById('alllocationsmap'), mapOptions );

    // Loop through array of markers & place each one on the map  
    for( i = 0; i < locations.length; i++ ) {
        var position = new google.maps.LatLng(locations[i].latitude, locations[i].longitude);
        bounds.extend(position);

        var marker = new google.maps.Marker({
            position: position,
            map: map,
            title: locations[i].title,
            icon: mappin
        }); 

        // Info window for each marker 
        google.maps.event.addListener(marker, 'click', (function(marker, i){
            return function() {
                infoWindow.setContent(locations[i].infowindow);
                infoWindow.open(map, marker);
                wpsl_all_locations_marker_clicked(marker, infoWindow)
            }
        })(marker, i));

        // Center the Map
        map.fitBounds(bounds);
        var listener = google.maps.event.addListener(map, "idle", function() { 
                if ( locations.length < 2 ) {
                map.setZoom(13);
            }
            google.maps.event.removeListener(listener); 
        });
    }

    // Fit the map bounds to all the pins
    var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
        google.maps.event.removeListener(boundsListener);
    });

    wpsl_all_locations_rendered(map);

} // loadmap()

});

1 个答案:

答案 0 :(得分:0)

您必须保持高度和宽度之间的某个比例。 特别是如果您的缩放级别很低。

我建议您至少将宽度固定为不是100%