网站模板中加入google地图代码,如何传递变量?

3 views
Skip to first unread message

mining

unread,
Nov 4, 2009, 5:31:42 AM11/4/09
to 谷歌地图 API 论坛
我的网站是静态页面的,每个静态页面都是由一个模板来生成的。

模板文件中,公司名称的显示方式代码如下:

<h1>$news[subject]</h1>

其中,$news[subject] 代表者公司的名称,每个生成的静态页面公司的名称都是不同的。

现在想要通过修改模板加入google地图代码,让每个页面根据公司的名称来显示公司在google地图中的位置。
这种方式要求访客在打开页面的时候,无需用户动手,google地图自动根据从$news[subject]获得的值,也就是公司名称显示该公司在地图
上的位置。


找到了一个网站,看见其能实现此种要求,网址:

http://xn--fiqs8sul1dtjf.net/%E7%BE%8E%E6%96%AF%E7%89%B9%E7%BD%97---%E5%8D%8E%E8%8F%B1%E5%88%B6%E8%A1%A3%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8.html

http://xn--fiqs8sul1dtjf.net/%E6%88%90%E9%83%BD%E9%98%B2%E8%BE%90%E5%B0%84%E7%BD%91.html

以上这两个网址就是这个网站上两个静态页面自动显示公司位置的例子,我精简了其中的google地图代码如下

header中的代码


</script><script src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=ABQIAAAA3yQdOWLCyutH1iSgviACSRRpyXdsl6qUn4PiK7Vw0vs-
rtXVNxSB2s0WW3na4SoZ6YWOGbutHQiXDw" type="text/javascript"></script>
<script type="text/javascript">
var map = null;
var geocoder = null;

function load() {
if (GBrowserIsCompatible()) {
geocoder = new GClientGeocoder();

function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
document.getElementById
("map").style.display="none";
} else {
map = new GMap2(document.getElementById
("map"));
map.setCenter(new GLatLng(37.4419,
-122.1419), 13);
map.addControl(new GSmallMapControl
());

map.setCenter(point, 13);

var marker = new GMarker(point);

var infoTabs = [
new GInfoWindowTab('地址','<b>美斯特罗---华菱
制衣有限公司</b><br>大河工业园丽友路2号 <br>保定市容城县, 河北,
071700<br>China<br>'),
new GInfoWindowTab('Directions',
'Enter your address:<br><form action="http://maps.google.com/maps"
method="get" target="_blank"><input type="text" size="40"
maxlength="60" name="saddr" id="saddr" value=""><br><input
class="button" value="Get Directions" type="submit"><input
type="hidden" name="daddr" value="大河工业园丽友路2号 +保定市容城县+河北+China"></
form>')];


GEvent.addListener(marker, 'click',
function() {
marker.openInfoWindowTabsHtml
(infoTabs);
});

map.addOverlay(marker);
marker.openInfoWindowTabsHtml(infoTabs);
}
}
);
}
}
showAddress("大河工业园丽友路2号 保定市容城县, 河北 071700
China");
}
}
</script>

body中的代码

<div id="map" style="width: 350px; height: 250px"></div>


现在的问题是我不知道该如何才能把$news[subject]这个变量放到上述的代码中实现地址解析?


illumin

unread,
Nov 4, 2009, 10:16:00 PM11/4/09
to 谷歌地图 API 论坛
showAddress("大河工业园丽友路2号 保定市容城县, 河北 071700
China"); 这句就是解析地址啊,你难道想让google解析你的公司名...

On Nov 4, 6:31 pm, mining <mine....@gmail.com> wrote:
> 我的网站是静态页面的,每个静态页面都是由一个模板来生成的。
>
> 模板文件中,公司名称的显示方式代码如下:
>
> <h1>$news[subject]</h1>
>
> 其中,$news[subject] 代表者公司的名称,每个生成的静态页面公司的名称都是不同的。
>
> 现在想要通过修改模板加入google地图代码,让每个页面根据公司的名称来显示公司在google地图中的位置。
> 这种方式要求访客在打开页面的时候,无需用户动手,google地图自动根据从$news[subject]获得的值,也就是公司名称显示该公司在地图
> 上的位置。
>
> 找到了一个网站,看见其能实现此种要求,网址:
>

> http://xn--fiqs8sul1dtjf.net/%E7%BE%8E%E6%96%AF%E7%89%B9%E7%BD%97---%...
>
> http://xn--fiqs8sul1dtjf.net/%E6%88%90%E9%83%BD%E9%98%B2%E8%BE%90%E5%...

Fei Chen

unread,
Nov 6, 2009, 5:24:04 AM11/6/09
to google-map...@googlegroups.com
应该是在你的php页面里面使用形如var name = <? echo($news[subject])?>这样的写法就可以吧
我没用过php,建议你看一下php相关的内容



2009/11/5 illumin <illu...@gmail.com>

Dorian

unread,
Nov 15, 2009, 1:47:59 AM11/15/09
to 谷歌地图 API 论坛
new GInfoWindowTab('地址','$news[subject]')
... ...
showAddress("<?php echo $news[subject];?>");

On 11月4日, 下午6时31分, mining <mine....@gmail.com> wrote:
> 我的网站是静态页面的,每个静态页面都是由一个模板来生成的。
>
> 模板文件中,公司名称的显示方式代码如下:
>
> <h1>$news[subject]</h1>
>
> 其中,$news[subject] 代表者公司的名称,每个生成的静态页面公司的名称都是不同的。
>
> 现在想要通过修改模板加入google地图代码,让每个页面根据公司的名称来显示公司在google地图中的位置。
> 这种方式要求访客在打开页面的时候,无需用户动手,google地图自动根据从$news[subject]获得的值,也就是公司名称显示该公司在地图
> 上的位置。
>
> 找到了一个网站,看见其能实现此种要求,网址:
>

> http://xn--fiqs8sul1dtjf.net/%E7%BE%8E%E6%96%AF%E7%89%B9%E7%BD%97---%...
>
> http://xn--fiqs8sul1dtjf.net/%E6%88%90%E9%83%BD%E9%98%B2%E8%BE%90%E5%...

Reply all
Reply to author
Forward
0 new messages