2011-07-12 12 views
1
<div> 
    {$google_map_link} 
</div> 

我將iframe代碼分配到smarty並嘗試在屏幕上顯示地圖。如何在smarty中顯示Google地圖代碼

分配給Smarty的變量 {$google_map_link}

谷歌地圖是

<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> 

我希望能在屏幕上顯示谷歌地圖,但只有iframe的代碼顯示

如何解決這個...

+1

看起來IFRAME應該加載罰款:http://jsfiddle.net/zpczQ/。我在猜測你分配給google_map_link的字符串有什麼問題。你能否包括確切的PHP代碼?您也可以查看瀏覽器源代碼中iframe的內容,以查看任何問題。 –

回答

1

在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中顯示Google地圖的最簡單方法。

我可以幫助一些別人

1

我試過你的代碼,它在Smarty 3.0.8上工作。

爲什麼不使用Google maps 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'); 
?> 

模板:

<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