1

我正在使用Google Maps for Javascript。我重新組織了所有選項,並確定了真正的位置。但是當我添加樣式和標記時,我看不到效果。我該如何解決它?我的地圖上的隱形風格

var locations = [ 
     ['MyLocation', 41.084951,29.016048], 
    ]; 


    var waStyle = [ 
      { 
       featureType: "all", 
       stylers: [ 
        { saturation: -100 } 
       ] 
      } 
     ]; 

    var map = new google.maps.StyledMapType(waStyle,{name: "MyLoc"}); 

    var img = new google.maps.MarkerImage("/themes/bc/images/bc_pin.png"); 

    var map = new google.maps.Map(document.getElementById('map_detail'), { 
     zoom: 10, 
     center: new google.maps.LatLng(41.084951,29.016048), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    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]), 
     map: map 
     }); 

     google.maps.event.addListener(marker, 'click', (function(marker, i) { 
     return function() { 
      infowindow.setContent(locations[i][0]); 
      infowindow.open(map, marker); 
     } 
     })(marker, i)); 

    } 

回答

1

使用你的代碼,我看到了標記。樣式不可見,因爲您不在地圖上使用它。

documentation

實際使用(從上面提到的文檔的一些評論你的代碼,並添加代碼)風格:

// Create a new StyledMapType object, passing it the array of styles, 
// as well as the name to be displayed on the map type control. 
var styledMap = new google.maps.StyledMapType(waStyle,{name: "MyLoc"}); 

var img = new google.maps.MarkerImage("mapIcons/marker1.png"); 

// Create a map object, and include the MapTypeId to add 
// to the map type control. 
map = new google.maps.Map(document.getElementById('map_canvas'), { 
    zoom: 10, 
    center: new google.maps.LatLng(41.084951,29.016048), 
    mapTypeId: google.maps.MapTypeId.ROADMAP, 
    mapTypeControlOptions: { 
    mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'] 
    } 
}); 

//Associate the styled map with the MapTypeId and set it to display. 
map.mapTypes.set('map_style', styledMap); 
map.setMapTypeId('map_style'); 

要使用已定義的標記圖標,將其包含在google.maps.Marker構造:

marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
    icon: img, 
    map: map 
    }); 

注意,如果你有一個以上的標記,你將不得不與在關聯問題帶標記的foWindow,可以通過函數關閉(createMarker函數)修復,是常見問題解答。

working example based off your code