gpt4 book ai didi

javascript - 在 iframe 中动态显示谷歌地图

转载 作者:行者123 更新时间:2023-11-30 17:22:21 24 4
gpt4 key购买 nike

我想在 javascript 中动态创建一个“谷歌地图”链接,然后将其设置为我的 iframe 的 src,但我不知道谷歌地图是否可行,因为这不起作用:

    document.getElementById('map_canvas').src='http://maps.google.com/maps/ms?ie=UTF8&msa=0&msid=209246852521822593612.0004feda304ac527ea40a&output=embed';

虽然,例如这个有效:

    document.getElementById('map_canvas').src='http://www.cnn.com';

这是我的 iframe:

<iframe id="map_canvas" name="map_canvas" width="100%" height="600px"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
src="">
</iframe>

你能解释一下吗,如何在 iframe 中动态生成和显示谷歌地图链接?

谢谢你的帮助!

最佳答案

我是这样解决的:我为每个 jQuery 添加了 iframe 并设置了所需的 src 属性。

function displayMapAt(lat, lon, zoom) {
$("#map")
.html(
"<iframe id=\"map_frame\" "
+ "width=\"100%\" height=\"600px\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" "
+ "src=\"https://www.google.sk/maps?f=q&amp;output=embed&amp;source=s_q&amp;hl=sk&amp;geocode=&amp;q=https:%2F%2Fwww.google.sk%2Fmaps%2Fms%3Fauthuser%3D0%26vps%3D5%26hl%3Dsk%26ie%3DUTF8%26oe%3DUTF8%26msa%3D0%26output%3Dkml%26msid%3D205427380680792264646.0004fe643d107ef29299a&amp;aq=&amp;sll=48.669026,19.699024&amp;sspn=4.418559,10.821533&amp;ie=UTF8&amp;ll="
+ lat + "," + lon
+ "&amp;spn=0.199154,0.399727&amp;t=m&amp;z="
+ zoom + "\"" + "></iframe>");

}

关于javascript - 在 iframe 中动态显示谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24914513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com