谷歌静态地图未加载

时间:2015-03-28 22:33:38

标签: php sql google-maps google-static-maps

我正在从要显示的SQL表中检索值,并且我想使用先前采用的纬度和经度坐标来显示静态地图。

<?php
if(isset($row["address"]))
{
    echo"<b>Address: </b>";
    echo $row["address"];
    echo "<br>";
}

$latitude = $row["latitude"];
$longitude = $row["longitude"];

$map = "https://maps.googleapis.com/maps/api/staticmap?center=".$latitude.",".$longitude."&zoom=13&size=300x300&key=[my key goes here]";
?>

<img src="$map">

我更新了密钥并单独测试了该链接,并在Chrome浏览器标签中正常加载。但是,当我尝试通过我的网页加载它时,地址部分加载正常,但不是地图,而是通常的图标,显示图片没有加载。 (没有足够的代表发布我实际输出的图片)。

这是我第一次使用API​​,欢迎任何帮助!

1 个答案:

答案 0 :(得分:1)

问题是你试图在PHP代码之外引用$ map变量

你可以试试这个

<?php
if(isset($row["address"]))
{
    echo"<b>Address: </b>";
    echo $row["address"];
    echo "<br>";
}

$latitude = $row["latitude"];
$longitude = $row["longitude"];

$map = "https://maps.googleapis.com/maps/api/staticmap?center=".$latitude.",".$longitude."&zoom=13&size=300x300&key=[my key goes      here]";

echo '<img src="'. $map . '">'
?>