//http://api.map.baidu.com/staticimage/v2
/**
* 根据经纬度或者地址来获取百度地图
* @param $center
*/
public static function staticimage($center) {
if(!$center) {
return '';
}
$data = [
'ak' => config('map.ak'),
'width' => config('map.width'),
'height' => config('map.height'),
'center' => $center,
'markers' => $center,
];
$url = config('map.baidu_map_url').config('map.staticimage').'?'.http_build_query($data);
// 1 file_get_contents($url);
// 2 curl
$result = doCurl($url);
return $result;
}
<?php
/**
* Created by PhpStorm.
* User: chenshu
* Date: 2018/2/16
* Time: 下午1:07
*/
return [
'ak' => 'RCqr5risuryquwlO8FINvNVwzYMRpbsq',
'baidu_map_url' => 'http://api.map.baidu.com/',
'geocoder' => 'geocoder/v2/',
'width' => 400,
'height' => 300,
'staticimage' => 'staticimage/v2',
];
public function map(){
return \Map::staticimage('北京昌平河沙地铁');
}
/**
* @param $url
* @param int $type 0 get 1 post
* @param array $data
*/
function doCurl($url, $type=0, $data=[]) {
$ch = curl_init(); // 初始化
// 设置选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER,0);
if($type == 1) {
// post
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
//执行并获取内容
$output = curl_exec($ch);
// 释放curl句柄
curl_close($ch);
return $output;
}