Save current Google Map view as an image

I have a database with some addresses. For each address the view of the map will be different.

Is there a way, for each address, to save the map view as an image?


 <img src='<?php echo 
 $MyAddress?>CA&zoom=14&size=500x500&markers=<?php echo $myAddress?>&sensor=false' alt=''/>

The center is where the map will be centered. The markers is the address you want so i put center=markers. Zoom is how close you want to zoom in the map Size the size you want of the picture. Take a look here

In this case you can use the Google Static Maps API, from here.

For storage and bandwidth purposes you can only storage the GeoPoint of the location and only render the image when the user requests it.

public static function getGoogleMapImage($params = array(), $saveTo = null, $https = true){
        //set default parameters
            $params['center'] = isset($params['center']) ? $params['center'] : 0;
            $params['zoom'] = isset($params['zoom']) ? $params['zoom'] : 0;
        $params['size'] = isset($params['size']) ? $params['size'] : '200x200';
        $params['sensor'] = isset($params['sensor']) ? $params['sensor'] : 'false';

        foreach($params as $name => $value){
            $paramString.=$name . '=' . urlencode($value) . '&';
        $paramString = trim($paramString, '&');

        $httpPrefix = $https ? 'https://' : 'http://';
        $imageUrl = $httpPrefix . '' . $paramString;

        if(!$saveTo){ //if you don't want to save image, just to display it
            return $imageUrl;

                case 'png8': $imgExt = '.png'; break; 
                case 'gif': $imgExt = '.gif'; break; 
                case 'jpg': $imgExt = '.jpg'; break; 
                case 'jpg-baseline': $imgExt = '.jpg'; break; 
                default: $imgExt = '.png';
            $imgExt = '.png';

        $saveTo = preg_replace("/\\.[^.\\s]{3,4}$/", "", $saveTo) . $imgExt; //in case requested file extension and provided in $saveTo don't match

        if(self::getImage($imageUrl, $saveTo)){
            return realpath($saveTo);

        return false;

I used curl call for getting images from created $imageUrl

Need Your Help

How can I identify a guest user for a time longer than session usually exists

php laravel session

I know, that I can use \Session::getId(). But it changes form time to time. Maybe I do not understand the sessions. As I know it starts when php runs and it is deleted when php code is finished. On...

How to create clientId and clientSecret for OAuthTokenCredential paypal rest api

paypal paypal-rest-sdk

I am using paypal rest api and i don't know how to create client_id and clientSecret. Please let me know if you have any idea...