2013-09-22 75 views
0

我米,谷歌地圖工作,我想隱藏,如果有可能我的地圖上的餐廳和酒店。 所以我的問題是如何消除或應用過濾器來隱藏餐廳和酒店點在谷歌地圖API。如何過濾谷歌地圖

感謝所有。 編輯。

<script> 
    function writeAddressName(latLng) { 
    var geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 
     "location": latLng 
    }, 
    function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) 
     document.getElementById("address").innerHTML = results[0].formatted_address; 
     else 
     document.getElementById("error").innerHTML += "Unable to retrieve your address" + "<br />"; 
    }); 
    } 


    function geolocationSuccess(position) { 
    var userLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
    writeAddressName(userLatLng); 

    $(document).ready(function(){ 
var styles = [ 
    { 
     stylers: [ 
      { hue: "#00ffe6" }, 
      { saturation: -20 } 
     ] 
    },{ 
     featureType: "road", 
     elementType: "geometry", 
     stylers: [ 
      { lightness: 100 }, 
      { visibility: "simplified" } 
     ] 
    },{ 
     featureType: "road", 
     elementType: "labels", 
     stylers: [ 
      { visibility: "off" } 
     ] 
    } 
]; 

var styledMap = new google.maps.StyledMapType(styles, {name: "Styled Map"}); 

// display map 
var mapOptions = { 
    zoom: 11, 
    center: userLatLng , 
    mapTypeControlOptions: { 
     mapTypeIds: [google.maps.MapTypeId.ROADMAP,'map_style'] 
    } 
}; 
var map = new google.maps.Map(document.getElementById('map'), mapOptions); 

map.mapTypes.set('map_style', styledMap); 
map.setMapTypeId('map_style', styledMap); 
}); 
    // marker 
    new google.maps.Marker({ 
     map: map_style, 
     position: userLatLng 
    }); 
+0

你只是渲染地圖或進行API調用? – nilgun

+0

MMH我不知道你的問題我只是讓使用谷歌地圖API推出地圖 – user2803925

回答

0

您的地圖樣式隱藏路線圖上的某些元素,例如 你正在尋找的API提示是google.maps.MapTypeStyle:可以在這裏找到如何使用它https://developers.google.com/maps/documentation/javascript/reference?hl=en#MapTypeStyle

例子: https://developers.google.com/maps/documentation/javascript/styling

在你的情況下,風格看起來在某種程度上是這樣的:

{ 
featureType: "poi.business", 
elementType: "labels", 
stylers: [ 
    { visibility: "off" } 
] 
} 

:編輯: 工作示例可以在這裏找到:http://jsfiddle.net/Elak/ndjC8/7/

var styles = [ 
    { 
     stylers: [ 
      { hue: "#00ffe6" }, 
      { saturation: -20 } 
     ] 
    },{ 
     featureType: "road", 
     elementType: "geometry", 
     stylers: [ 
      { lightness: 100 }, 
      { visibility: "simplified" } 
     ] 
    },{ 
     featureType: "road", 
     elementType: "labels", 
     stylers: [ 
      { visibility: "off" } 
     ] 
    } 
]; 

// 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(styles, {name: "Styled Map"}); 

// Dessin de la map 
var mapOptions = { 
    zoom: 11, 
    center: new google.maps.LatLng(55.6468, 37.581), 
    mapTypeControlOptions: { 
     mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style'] 
    } 
}; 
var map = new google.maps.Map(document.getElementById('map'), mapOptions); 

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

感謝您的幫助埃拉javascript中的地圖,但我沒有成功,我必須承認,IMA初學者使用JavaScript和我使用它,準時 – user2803925

+0

你真的必須閱讀如何設置這個文件。涉及到更多的代碼。 下面是一個例子:http://jsfiddle.net/Elak/ndjC8/7/ – MichaC

+0

好的,謝謝你幫我埃拉有一些故障排除,以顯示地圖,我不知道爲什麼。我今天下午試了一下才明白,但沒有發現。我需要更多的工作。 – user2803925