我正在使用谷歌地图API v3。我想在默认的Google地标/ poi上停用点击操作。例如,当我缩放到UCLA时,学校图标显示(这很好),但我不希望用户单击并查看该位置的详细信息。我应该使用哪个API函数?禁用谷歌地图上的可点击地标
回答
我遇到了同样的问题。 Google似乎最近更改了自己的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);
以下解决方案的工作,但因为它依赖于定制风格的地图图块,免费地图仅限于(每天2,500张地图加载) - See Google Maps FAQ。
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');
}
只是阅读它,它看起来会完全隐藏标记,而不是简单地让它们不可点击。那是对的吗? –
这是正确的。对于让他们可见的非官方(不稳定)解决方案,请参阅上面关于强制使用早期API版本的问题。如果你找到更好的解决方案,我很乐意听到它。 – Glenn
谢谢!这完全有帮助。 :) –
此问题已被记录与谷歌在:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3866
请明星,在这个问题上发表评论,您的需求在那里。
我明白,这个问题是旧的,但也许这个答案将帮助别人:
我不知道这是否是合法的,但我最终探索代码,并作出这样的:
$("#google-map").on("mousedown",function(){
setTimeout(function(){
disableInfoWindows();
},500);
});
function disableInfoWindows()
{
$(".gm-iw.gm-sm").parent().parent().remove();
$("[style='position: absolute; left: -2px; top: -336px; width: 59px; height: 492px; -webkit-user-select: none; border: 0px; padding: 0px; margin: 0px;']")
.parent()
.parent()
.remove();
}
它为我工作,没有infoWindow显示,同时保留所有的图标。任何有想法加强代码的人都会受到欢迎,infoWindow在第一次打开时显示出来,在第一次打开之后,它完全消失了。
据我所知,OP希望有一个解决方案能够保留标签/图标,但会暂停点击事件。我不确定这是可能的;请star this issue
但是,我们中的一些人正在绘制形状sans绘图管理器和标签/图标阻碍了新点的添加。如果它符合您的要求,您可以暂时删除图标/标签。我发现,中转,POI和景观都需要切换:
var map = new google.maps.Map(document.getElementById("map"), {});
map.poi = function(state){
var styles = [
{
"featureType": "transit",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "poi",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "landscape",
"stylers": [
{ "visibility": "off" }
]
}
];
this.set("styles", (state)? {} : styles);
}
和使用:
//turn the labels/icons off
map.poi(false);
//turn them back on
map.poi(true);
谷歌已经暴露了这个选项。见google.maps.MapOptions
in the docs的clickableIcons
。
实例初始化代码:
map = new google.maps.Map(document.getElementById('map'), {
clickableIcons: false
});
这真的应该被标记为现在的答案。 – keaukraine
将此选项添加到mapOption clickableIcons:假
这是更多的选择,我认为你会
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.
- 1. 点击Google地图上的谷歌地图标记
- 2. 点击谷歌地图上的地方标记javascript api
- 3. 谷歌地图标记点击事件
- 4. 标记事件点击谷歌地图
- 5. 谷歌地图点击标记
- 6. 触发谷歌地图标记点击
- 7. 谷歌地图可点击侧边栏
- 8. 在谷歌地图上点击'Google'
- 9. 谷歌地图 - 可点击标记的标记群集
- 10. 谷歌地图 - 点击标记点击加载窗口点击
- 11. 如何通过点击谷歌地图标记目标地图上的元素
- 12. 角度谷歌地图信息窗口图标不可点击
- 13. 谷歌地图V3 “如何创建在地图标记点击”
- 14. 谷歌地图关闭标记点击地图
- 15. 谷歌地图 - 标记点击中心地图
- 16. 谷歌地图var城市地图区域可点击
- 17. 谷歌地图谷歌地点类型
- 18. 谷歌地图android api 2:默认的标记不可点击
- 19. 在Android的谷歌地图点击标记显示地址?
- 20. 谷歌地图在地图上添加信息窗口点击
- 21. Android谷歌地图V2 - 在几个标记上的OnInfoWindowClick点击
- 22. Android的谷歌改变地图标记上点击
- 23. 如何获得角度谷歌地图上的点击坐标?
- 24. mouseover,mouseout并点击谷歌地图上的同一个标记
- 25. 更改多个谷歌地图标记的位置上点击
- 26. 点击谷歌地图上的重叠标记与水豚 - webkit
- 27. 如何点击Xamarin UITest谷歌地图上的标记
- 28. 谷歌地图v3上可点击的行车路线
- 29. 谷歌地图上的CSS按钮不可点击
- 30. 谷歌地图点击动画特定标记点击
我发现空气中的一个例子bnb地图搜索。他们禁用了地标点击而没有隐藏地标。他们是如何做到的呢? – Clark
我认为你可以强制他们api的早期版本,比如说3.3或3.4,它可能会起作用,或者你可以使用我在下面发布的最新API的解决方案。 – Glenn
我会试一试。谢谢。 – Clark