如何移除Google Maps嵌入代码中的Directions按钮?
移除Google Maps嵌入模块的Directions按钮方案
方法一:修改Embed代码的src参数(无需API,推荐)
直接在Google Maps嵌入的URL末尾添加&disableDefaultUI=true参数,即可隐藏所有默认UI控件,包括Directions按钮。这种方法零代码经验也能操作,快速解决问题。
示例修改:
原嵌入代码(类似):
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3009.xxxx!2d28.97xxxx!3d41.01xxxx!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14cab9xxxx!2sExample%20Business!5e0!3m2!1sen!2str!4v16xxxxxx" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
修改后添加参数:
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3009.xxxx!2d28.97xxxx!3d41.01xxxx!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14cab9xxxx!2sExample%20Business!5e0!3m2!1sen!2str!4v16xxxxxx&disableDefaultUI=true" width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
注意:这个参数会隐藏所有默认控件(缩放按钮、地图类型切换等),目前Google Maps Embed API不支持细粒度单独隐藏Directions按钮,只能全关或全留。
方法二:使用Google Maps JavaScript API v3(进阶)
如果需要更灵活的控件控制(比如只隐藏Directions按钮,保留其他UI),可以用API v3,但需要一定的JS基础和API密钥:
- 前往Google Cloud平台申请Maps JavaScript API密钥(需绑定结算账户,有免费配额)
- 替换页面中的Embed代码为以下结构:
<div id="map" style="width:600px;height:450px;border:0;"></div> <script> function initMap() { // 替换为企业实际经纬度 const businessLocation = { lat: 41.01xxxx, lng: 28.97xxxx }; const map = new google.maps.Map(document.getElementById("map"), { zoom: 15, center: businessLocation, disableDefaultUI: false, directionsControl: false, // 单独关闭Directions按钮 zoomControl: true, // 保留缩放控件 mapTypeControl: true, // 保留地图类型切换 streetViewControl: false // 可选:关闭街景控件 }); // 添加企业标记 new google.maps.Marker({ position: businessLocation, map: map, title: "企业名称" }); } </script> <!-- 替换YOUR_API_KEY为你的实际密钥 --> <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"></script>
这个方案能精准控制每个控件,但需要你了解基础的HTML/JS,且API调用超过免费配额会产生费用。
内容的提问来源于stack exchange,提问作者Terry
相关产品推荐
相关产品推荐

