保存并显示Google地图图片

时间:2014-04-06 11:27:29

标签: php google-maps

我有一个网站(guidemanche.com)直接从Googlemaps加载静态地图图片。如果您连接到Internet,它可以正常工作。但是,如果我断开连接,或者如果在CD上进行网站复制,则不再有图像。 所以,我想DL创建的图像,将其存储在服务器上,并将其作为jpg文件显示在我的页面中。 但它没有用,我有一个黑色的图像。

我的代码是:

<?php
$url="http://maps.google.com/maps/api/staticmap?center=[(#LATITUDE|scannav)],[(#LONGITUDE|scannav)]&zoom=14&size=450x400&maptype=hybrid&format=jpg&markers=color:blue|label:W|[(#LATITUDE|scannav)],[(#LONGITUDE|scannav)]&sensor=false";

$filename="googleimg/#ID_ARTICLE.jpg";

if (!$handle = fopen($url, 'r')) {
echo "Impossible d'ouvrir le fichier ($filename)";
exit;
}

$contents = stream_get_contents($handle);
fclose($handle);

$handle2=fopen($filename, 'w');
// Ecrivons quelque chose dans notre fichier.
if (fwrite($handle2, $contents) == FALSE) {
echo "Impossible d'écrire dans le fichier ($filename)";
exit;
}

fclose($handle2);
?>

其中#ID_ARTICLE是Spip(CMS)函数。

如何将GoogleMaps代码参数化以获得良好的图像并将其恢复? THKS

0 个答案:

没有答案
相关问题