将当前 Google 地图视图保存为图像

发布于 2024-12-12 01:33:48 字数 72 浏览 0 评论 0原文

我有一个包含一些地址的数据库。对于每个地址,地图的视图都会不同。

有没有办法,对于每个地址,将地图视图保存为图像?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

故事↓在人 2024-12-19 01:33:48
 <img src='http://maps.googleapis.com/maps/api/staticmap?center=<?php echo 
 $MyAddress?>CA&zoom=14&size=500x500&markers=<?php echo $myAddress?>&sensor=false' alt=''/>

中心是地图的中心位置。
标记是你想要的地址,所以我把 center=markers 。
缩放是您想要将地图放大到多大程度
调整您想要的图片尺寸。
看看这里
http://code.google.com/intl/el- GR/apis/maps/documentation/staticmaps/

 <img src='http://maps.googleapis.com/maps/api/staticmap?center=<?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
http://code.google.com/intl/el-GR/apis/maps/documentation/staticmaps/

潜移默化 2024-12-19 01:33:48

在这种情况下,您可以使用此处的 Google Static Maps API。

出于存储和带宽目的,您只能存储该位置的 GeoPoint,并且仅在用户请求时渲染图像。

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.

梦毁影碎の 2024-12-19 01:33:48
public static function getGoogleMapImage($params = array(), $saveTo = null, $https = true){
        //set default parameters
        if(!isset($params['markers'])){
            $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 . 'maps.googleapis.com/maps/api/staticmap?' . $paramString;

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

        if(isset($params['format'])){
            switch($params['format']){
                case 'png8': $imgExt = '.png'; break; 
                case 'gif': $imgExt = '.gif'; break; 
                case 'jpg': $imgExt = '.jpg'; break; 
                case 'jpg-baseline': $imgExt = '.jpg'; break; 
                default: $imgExt = '.png';
            }
        }else{
            $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;
    }

我使用curl调用从创建的$imageUrl获取图像

public static function getGoogleMapImage($params = array(), $saveTo = null, $https = true){
        //set default parameters
        if(!isset($params['markers'])){
            $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 . 'maps.googleapis.com/maps/api/staticmap?' . $paramString;

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

        if(isset($params['format'])){
            switch($params['format']){
                case 'png8': $imgExt = '.png'; break; 
                case 'gif': $imgExt = '.gif'; break; 
                case 'jpg': $imgExt = '.jpg'; break; 
                case 'jpg-baseline': $imgExt = '.jpg'; break; 
                default: $imgExt = '.png';
            }
        }else{
            $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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文