这里有两个答案,一个是摆脱信息框,另一个是在信息框中找到正确位置的答案。希望其中一位能有所帮助。
删除信息框
CAVEAT:此处的方法可能被视为“黑客”,如果 Google 更改其底层嵌入功能,可能会发生变化。
我最终在这里寻找类似的答案,并且根据其他人的说法,我想出了这个。答案与其他人相似,但希望能解释一些关于嵌入 url 以及如何使用 lat、long 和 zoom 生成嵌入 url(您可能从 CMS 中的位置插件中获得的东西)。
使用这篇文章作为搜索的基础,我发现了几篇不同的文章,概述了嵌入参数的细分,这些文章本身很有趣:-
Decoding the Google Maps embedded parameters,导致这里http://blog.themillhousegroup.com/2016/08/deep-diving-into-google-pb-embedded-map.html
我从那些文章中得到的(我不会在这里再次解释所有内容)是对“pb”参数的细分。 “pb”是一种专有(?)格式,“m”是一个矩阵引用。此处显示的是从 Google 地图嵌入共享生成的嵌入代码示例。
<iframe src="https://www.google.com/maps/embed?pb=
!1m18
!1m12
!1m3
!1d2256.8774176856136
!2d145.01353351606252
!3d-37.79291244062522
!2m3
!1f0
!2f0
!3f0
!3m2
!1i1024
!2i768
!4f13.1
!3m3
!1m2
!1s0x0%3A0x0
!2zLTM3Ljc5MjkxNjcgMTQ1LjAxNTcyMjI
!5e0
!3m2
!1sen
!2suk
!4v1532346966021
" width="600" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
通过玩弄,我发现整个“pb”参数可以简化为
<iframe src="https://www.google.com/maps/embed?pb=
!1m7
!1m2
!1m1
!1d2256.8774176856136
!3m3
!1m2
!1s0
!2zLTM3Ljc5MjkxNjcgMTQ1LjAxNTcyMjI
" width="450" height="450" frameborder="0" style="border:0" allowfullscreen></iframe>
注意:“m”后面的数字减少表示“矩阵”中的项目较少
以上嵌入适用于 lat = -37.7929167、long = 145.0157222 和 zoom = 17
的位置
正如另一个答案中所暗示的那样,似乎如果您只使用纬度和经度(使用此嵌入 API,而不是嵌入位置 API),则不会出现信息框,但我需要知道如何获取嵌入url 无需先通过 google 从共享中生成 url。
在“pb”分解中,有几个部分需要注意
- 地图比例1d2256.8774176856136
- 坐标2zLTM3Ljc5MjkxNjcgMTQ1LjAxNTcyMjI
这个比例可以从我在https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to 和https://www.esri.com/arcgis-blog/products/product/mapping/how-can-you-tell-what-map-scales-are-shown-for-online-maps/ 找到的算法得出
但我发现它与我期望的数字不太相符,所以我调整了缩放级别来给我
var mapScale = 591657550.5 / Math.pow( 2, zoom + 1);
// The results of this goes after the "1d" part in the map scale
对于坐标,在 lat 和 long 上使用 base64(所示示例用于 javascript)来获取结果字符串。我已经使用十进制度和度分秒格式工作了。
var base64 = btoa([lat,long]); // lazy "lat,long" formatting
// the result of this goes after the "2z" part in the coordinate
如果您想编写此脚本,这里有一个使用 javascript 生成 iframe 的简单示例,但您可能希望创建整个 src 服务器端。请注意:这不是关于 javascript 解决方案,而是脚本解决方案的示例。
// create the iframe and with the required properties.
var iframe = document.createElement("iframe");
iframe.width = 450;
iframe.height = 450;
iframe.frameborder = 0;
iframe.style.border = 0;
iframe.setAttribute('allowFullScreen', '')
document.body.appendChild(iframe)
// sample lat and long.
var lat = -37.7929167;
var long = 145.0157222;
var zoom = 17;
// get the scale
var mapScale = 591657550.500000 / Math.pow( 2, zoom+1);
// get the base64 representation
var base64 = btoa([lat,long]); // lazy "long,lat" formatting
// set the source of the iframe
iframe.src = 'https://www.google.com/maps/embed?key=asdfsdfsf&pb=!1m7!1m2!1m1!1d' + mapScale + '!3m3!1m2!1s0!2z' + base64;
我在 codepen 上创建了一个示例,显示了原始嵌入、缩小的嵌入、没有比例的嵌入和脚本解决方案。 https://codepen.io/mcgern/pen/zLZJmQ
信息框中的正确地名
您可能已经尝试过此操作,但如果您要添加的商家有 Google 地点 ID,您可以使用 https://developers.google.com/places/place-id 找到它。获得地点 id 后,您可以像这样在地点嵌入 url 中使用它
<iframe width="600" height="450" frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?q=place_id:ChIJ02vd-
4QOZ0gR4ZG28bSShpk&key=<INSERT_API_KEY>" allowfullscreen></iframe>
(我随便找了一个地方,看起来和爱尔兰教练是同一栋楼)