我想要两个地址的路线图图像,我已经尝试过 Google map API 和 MapQuest API,我想要静态图像中的数据,以便我可以使用该图像生成 PDF 文件,我该怎么做
我试过 起始地址是 6100 Richmond Ave, Houston TX 77057
谷歌地图
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
$address = $data['address1'].$data['address2']." ".$data['state']." ".$data['city']." ".$data['zip'];
$address = urlencode($address);
$url = "http://maps.googleapis.com/maps/api/staticmap?size=710x300&sensor=true";
$url .= "&path=color:0x0000ff|weight:10|6100+Richmond+Ave+Houston+TX+77057";
$url .= "|".$address ;
$url .= "&markers=color:red|label:A|6100+Richmond+Ave+Houston+TX+77057";
$url .= "&markers=color:green|label:B|".$address;
grab_image($url, $upload_dir.$plan['ID'].".png");
MapQuest 地图
先报废经纬度各源地址和目的地址
function getLatLong($myaddress) {
$myaddress = urlencode($myaddress);
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$myaddress."&sensor=false";
//get the content from the api using file_get_contents
$getmap = file_get_contents_curl($url);
//the result is in json format. To decode it use json_decode
$googlemap = json_decode($getmap);
//get the latitute, longitude from the json result by doing a for loop
foreach($googlemap->results as $res){
$address = $res->geometry;
$latlng = $address->location;
//$formattedaddress = $res->formatted_address;
return $latlng;
}
}
http://open.mapquestapi.com/staticmap/v4/getmap?size=600,200&zoom=14&shapeformat=cmp¢er=40.770021,-73.984003&shape=y_zwFjsrbMxWkz@??}DoC??a@}CyBt@ySiN??fDeP&scenter=40.77069,-73.992378&ecenter=40.770935,-73.97644
形状检查这个链接 http://www.mapquestapi.com/common/encodedecode.html
我怎样才能通过道路获得路线,或者我们可以在地图上以图像格式说出行车路线。