默认情况下,Google地图v3地形视图

时间:2011-12-22 16:41:27

标签: javascript google-maps-api-3

我正在尝试将我的谷歌地图嵌入默认为地形视图。附加的是我的代码,除了我将默认视图设置为terrain的地图选项之外,所有代码都正确加载。我将它设置为仅将选项限制为仅限地形,但是当您最初加载页面时,它位于默认的混合视图中。

var map, marker, latLngToPixel;
var middle_earth_MORADOR = new google.maps.LatLng(38, 0);

function initialize() {

    var mapOptions = {
        zoom: 2,
        center: middle_earth_MORADOR,
        backgroundColor: "#000",
         mapTypeControlOptions: {
             mapTypeIds: [google.maps.MapTypeId.TERRAIN]
         },
         mapTypeId: google.maps.MapTypeId.TERRAIN
    };

    var locations = [
        // PHP LOOP FOR FEATURED PROJECTS   
    ];

    map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);

    var styledMapOptions = {
        map: map,
        name: "map"
    }

    var build =  new google.maps.StyledMapType(styledMapOptions);
    map.mapTypes.set('map', build);
    map.setMapTypeId('map');
    var infowindow = new google.maps.InfoWindow();
    var marker, i;

    for (i = 0; i < locations.length; i++) {    

        marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            icon: 'http://staging.******.com/css/images/pin.png',
            map: map,
        });

         marker.setAnimation(google.maps.Animation.DROP);
         setTimeout(function(){ marker.setAnimation(null); }, 1750);

        google.maps.event.addListener(marker, 'click', (function(marker, i) {
            return function() {
                window.location = "http://staging.******.com/projects/" + locations[i][4];
            }
        })(marker, i));
    }
}

2 个答案:

答案 0 :(得分:2)

我认为您可以通过将属性disableDefaultUI设置为true来禁用地图的默认用户界面,然后在TERRAIN选项中设置为mapTypeId,如下所示。 :

function loadMap() {
var myLatlng = new google.maps.LatLng(lat,lan);
  var myOptions = {
    zoom: 3,
    center: myLatlng,
    disableDefaultUI: true,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  };
   map = new google.maps.Map(document.getElementById("map"), myOptions);
//code
}

答案 1 :(得分:0)

const map = new window.google.maps.Map(document.getElementById('Map'), {  

  mapTypeId: 'terrain'

});