How to save google image map api image on my server

Is it possible to save google image API as image on my server?

Background: The Google map image API generates an image of the desired location. Every time I call an external URL. Can I save a map image as an image (png, gif) on my server? This will improve the speed of my webpage. I tried with a twist, but could not copy the image

The requested URL is http://maps.googleapis.com/maps/api/staticmap?center=15719+OAKLEAF+RUN+DRIVE%2CLITHIA%2CFL%2C33547%2CUS& scaling = 8 & size = 150x100 & bullets = color: blue | labels: S | 11211 & sensor = false

+8
php google-maps
source share
4 answers

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); ?> 
+9
source share

you can read this url easily using file_get_contents

a fragment 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)); 
+3
source share

It's 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"; } 

the image is always returned in png format; you can specify the image a unique name by lat lng value or using the php time () function

+1
source share

Check out the Maps API for mobile. There you will get an image instead of an HTML map.

0
source share

All Articles