是否可以将Google地图图像API作为图像保存到我的服务器?
背景:Google地图图片API正在生成所需位置的图片。每次我要求外部URL。我可以将地图图像保存为服务器上的图像(png,gif)吗?这将提高我的网页速度。我尝试使用卷曲但未能复制图像
答案 0 :(得分:14)
<?php
$image = file_get_contents('http://maps.googleapis.com/maps/api/staticmap?center=15719%20OAKLEAF%20RUN%20DRIVE,LITHIA,FL,33547,US&zoom=8&size=150x100&markers=color%3ablue%7Clabel%3aS%7C11211&sensor=false');
$fp = fopen('ae.png', 'w+');
fputs($fp, $image);
fclose($fp);
unset($image);
?>
答案 1 :(得分:4)
您可以使用file_get_contents
轻松阅读该网址的代码段将是
$url='http://maps.googleapis.com/maps/api/staticmap?center=15719+OAKLEAF+RUN+DRIVE%2CLITHIA%2CFL%2C33547%2CUS&zoom=8&size=150x100&markers=color:blue|label:S|11211&sensor=false';
file_put_contents('filename.png',file_get_contents($url));
答案 2 :(得分:2)
这很容易
只需使用
if(@copy('http://maps.googleapis.com/maps/api/staticmap?center=15719%20OAKLEAF%20RUN%20DRIVE,LITHIA,FL,33547,US&zoom=8&size=150x100&markers=color%3ablue%7Clabel%3aS%7C11211&sensor=false', '/where-u-want-to-save/your-given-name.png')){
echo "image-saved";
}else{
echo "failed"; }
图像始终以png格式返回 你可以通过lat lng值或使用php time()函数给图像一个唯一的名称
答案 3 :(得分:0)
检查Maps API for mobile。在那里,您将收到一张Image而不是一张HTML地图。