禁用谷歌地图上的可点击地标

Cla*_*ark 24 google-maps-api-3

我正在使用谷歌地图API v3.我想禁用默认google landmark/poi上的点击操作.例如,当我缩放到UCLA时,学校图标显示(这很好),但我不希望用户单击并查看该位置的详细信息.我应该使用哪种API函数?

Pat*_*ley 33

谷歌已经公开了一个选项.见clickableIconsgoogle.maps.MapOptions 在文档中.

示例初始化代码:

map = new google.maps.Map(document.getElementById('map'), {
    clickableIcons: false
});
Run Code Online (Sandbox Code Playgroud)

  • 现在确实应该将此标记为答案。 (2认同)

Gle*_*enn 7

我遇到了同样的问题.谷歌似乎最近更改了他们的API以使基本地图标签"可点击",并且还没有简单的API调用来禁用他们的可点击性. http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/f1ac9ad4da3606fe

我想看看谷歌添加这样一个简单的地图选项,但唉它还不存在

var opts = { clickableLabels:false };
var map = new maps.google.com.map(div,opts);
Run Code Online (Sandbox Code Playgroud)

以下解决方案有效,但由于它依赖于自定义样式的地图图块,因此免费地图仅限于(每天2,500个地图加载) - 请参阅Google地图常见问题解答.

function initialize() {

  // For more details see 
// http://code.google.com/apis/maps/documentation/javascript/styling.html
  var noPOILabels = [
    { 
      featureType: "poi", 
      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 noPOIMapType = new google.maps.StyledMapType(noPOILabels,
    {name: "NO POI"});

  // Create a map object, and include the MapTypeId to add
  // to the map type control.
  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(55.6468, 37.581),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'no_poi']
    }
  };
  var map = new google.maps.Map(document.getElementById('map_canvas'),
    mapOptions);

  //Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('no_poi', noPOIMapType);
  map.setMapTypeId('no_poi');
}
Run Code Online (Sandbox Code Playgroud)


duh*_*hok 5

将此选项添加到mapOption clickableIcons:false

这是我认为你会更多的选择

draggable: true, // this is for disable the Draggable
disableDefaultUI: true, // this for disable Default UI
fullscreenControl: false, // this is for disable Full Screen
scrollwheel: true, // this is for disable Scroll Wheel
disableDoubleClickZoom: false, // this is for disable Double Click Zoom
draggableCursor:'crosshair',// this is for cursor type
draggingCursor:'move', // this is for dragging cursor type
minZoom: 3, // this is for min zoom for map
maxZoom: 18 , // this is for max zoom for map
//note : max, min zoom it's so important for my design.
zoom: 14, // this is to make default zoom
clickableIcons: false, // this is to disable all labels icons except your custom infowindow or Infobox.
Run Code Online (Sandbox Code Playgroud)