如何在网站的iframe上获取Google Maps路线规划器

时间:2013-09-08 19:14:13

标签: html wordpress forms google-maps iframe

我正在编写一个新的(wordpress)网站,并且有一个“联系人”菜单项。在这个菜单项中,我得到了一张地图(Google Maps iframe的代码)。现在我应该在地图下有一个路线规划器。为此,我得到了一些代码:

<form name="search_route" method="get" action="http://maps.google.com/" target="_blank">
        <input name="saddr" type="text" id="saddr">
        <input name="daddr" type="hidden" id="daddr" value="Empire State Building, 350 5th Avenue, New York, NY, USA">
        <input type="submit" name="Submit" value="Submit">
    </form>

我的问题:代码正在运行,但它像我告诉表单一样链接到maps.google.com。但路线应该计划在页面上的iframe而不是打开另一个链接。这可能吗?如果是,有人可以给我一个提示吗?

提前致谢

干杯

1 个答案:

答案 0 :(得分:4)

采样代码:

<form method="get" action="https://www.google.com/maps" target="mapframe">
        <input name="saddr" type="text" id="saddr">
        <input name="output" type="hidden" value="embed">
        <input name="f" type="hidden" value="d">
        <input name="z" type="hidden" value="11">
        <input name="daddr" type="hidden" id="daddr" 
               value="Empire State Building, 350 5th Avenue, New York, NY, USA">
        <input type="submit" name="Submit" value="Submit">
</form>
<iframe 
  name="mapframe" width="425" height="350" 
  src="https://www.google.com/maps?z=11&amp;f=d&amp;output=embed&amp;ll=40.7902,-73.9597">
</iframe>

表单的action必须为https://www.google.com/maps
表单的target必须等于name

iframe

通过嵌入代码的iframe-src为每个参数添加隐藏的输入(至少需要output:embed的字段)

演示:http://jsfiddle.net/doktormolle/3JsuM/