如何在 smarty 中显示谷歌地图代码

发布于 2024-11-19 23:17:39 字数 1137 浏览 2 评论 0原文

<div>
    {$google_map_link}
</div>

我将以下谷歌地图 iframe 代码分配给 smarty 并尝试在屏幕上显示地图。

分配给 smarty 变量 {$google_map_link} 的 google 地图是

<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.in/maps?q=Tiriyos&amp;gl=in&amp;hl=en&amp;sll=13.008237,80.193329&amp;sspn=0.206059,0.363579&amp;ie=UTF8&amp;view=map&amp;cid=5721197682818793762&amp;hq=Tiriyos&amp;hnear=&amp;ll=12.948405,80.137217&amp;spn=0.006441,0.011362&amp;iwloc=A&amp;output=embed"></iframe>
<br />
<small>
    <a href="http://maps.google.co.in/maps?q=Tiriyos&gl=in&hl=en&sll=13.008237,80.193329&sspn=0.206059,0.363579&ie=UTF8&view=map&cid=5721197682818793762&hq=Tiriyos&hnear=&ll=12.948405,80.137217&spn=0.006441,0.011362&z=17" style="color:#0000FF;text-align:left">View Larger Map</a>
</small>

我希望在屏幕上显示 google 地图,但只显示 iframe 代码

如何解决这个...

<div>
    {$google_map_link}
</div>

I am assigning the following google map iframe codes into smarty and trying to display map on the screen.

google map that assigned to smarty variable {$google_map_link} is

<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.in/maps?q=Tiriyos&gl=in&hl=en&sll=13.008237,80.193329&sspn=0.206059,0.363579&ie=UTF8&view=map&cid=5721197682818793762&hq=Tiriyos&hnear=&ll=12.948405,80.137217&spn=0.006441,0.011362&iwloc=A&output=embed"></iframe>
<br />
<small>
    <a href="http://maps.google.co.in/maps?q=Tiriyos&gl=in&hl=en&sll=13.008237,80.193329&sspn=0.206059,0.363579&ie=UTF8&view=map&cid=5721197682818793762&hq=Tiriyos&hnear=&ll=12.948405,80.137217&spn=0.006441,0.011362&z=17" style="color:#0000FF;text-align:left">View Larger Map</a>
</small>

I expect to display the google map on screen but only iframe codes are displayed

How to solve this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千里故人稀 2024-11-26 23:17:39

我已经尝试过你的代码,它可以在 Smarty 3.0.8 上运行。

为什么不使用 Google 地图 API (http://code.google.com/apis/maps/index.html)?
我通常将 html 放入模板中并只传递值。示例如下:

php:

<?php
$smarty->assign('google_map_x', '12.948405');
$smarty->assign('google_map_y', '80.137217');
?>

template:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
  var myLatlng = new google.maps.LatLng({$google_map_x}, {$google_map_y});
  var myOptions = {
    zoom: 8,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  var marker = new google.maps.Marker({
    position: myLatlng, 
    map: map, 
    title:"Tiriyos"
  }); 
}
</script>
<div id="map_canvas" style="width:300px;height:300px"></div>

然后您可以将信息窗口放在标记上。请在此处了解详情:http://code.google.com/apis /maps/documentation/javascript/overlays.html#InfoWindows

I've tried your code and it works on Smarty 3.0.8.

Why don't you use Google maps API (http://code.google.com/apis/maps/index.html)?
I usualy put html into the template and just pass the values. Example below:

php:

<?php
$smarty->assign('google_map_x', '12.948405');
$smarty->assign('google_map_y', '80.137217');
?>

template:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
  var myLatlng = new google.maps.LatLng({$google_map_x}, {$google_map_y});
  var myOptions = {
    zoom: 8,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  var marker = new google.maps.Marker({
    position: myLatlng, 
    map: map, 
    title:"Tiriyos"
  }); 
}
</script>
<div id="map_canvas" style="width:300px;height:300px"></div>

Then you can put your info window on your marker. Read more here: http://code.google.com/apis/maps/documentation/javascript/overlays.html#InfoWindows

美人如玉 2024-11-26 23:17:39

在 php

<?
$google_map_link = html_entity_decode($google_map_code);
$smarty->assign('google_map_link', $google_map_link);
?>

在 HTML

<div>
    {$google_map_link}
</div>

中,我使用 html_entity_decode 来解码谷歌地图 iframe 代码并在 smarty 中显示。这是在 smarty 中显示谷歌地图的最简单方法。

我可以帮助别人

In php

<?
$google_map_link = html_entity_decode($google_map_code);
$smarty->assign('google_map_link', $google_map_link);
?>

In HTML

<div>
    {$google_map_link}
</div>

I had used html_entity_decode to decode google maps iframe code and displayed in smarty. This is easiest way to display google maps in smarty.

I may help some one else

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文