简体   繁体   English

如何将google图像映射API图片保存到我的服务器

[英]How do I save the google image map API picture to my server

Is it possible to save the google map image API as an image to my server? 是否可以将谷歌地图图像API作为图像保存到我的服务器?

Background: Google map image API is generating an image of the desired location. 背景: Google地图图像API正在生成所需位置的图像。 Every time I am calling for the external URL. 每次我要求外部URL。 Can I save the map image as an image(png, gif) on my server? 我可以将地图图像保存为服务器上的图像(png,gif)吗? This will improve my web page speed. 这将提高我的网页速度。 I tried with curl but failed to copy the image 我尝试使用卷曲但未能复制图像

Requested 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 请求的网址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=假

you can try something like this: 你可以尝试这样的事情:

<?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);
?>

you can easily read that url using file_get_contents 您可以使用file_get_contents轻松读取该URL

snippet for this will be 这个片段就是

$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));

This is really easy 这真的很容易

just use 只是用

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"; }

image always returns as png format you may give image a unique name by lat lng value or using php time() function 图像始终以png格式返回,您可以通过lat lng值或使用php time()函数为图像指定唯一的名称

Check the Maps API for mobile. 查看Maps API for mobile。 There you will receive an Image instead of a HTML map. 在那里,您将收到一张Image而不是一张HTML地图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM