Isprovociran koleginim postom (joke), napravih da bude kako i treba.
PHP kôd:
class VM{
/**
* ViaMichelin.com PHP Class (4.12.2010)
* @author Webarto.com
* @copyright 2010
*/
public function generateLink($from, $to){
return '<a href="http://www.viamichelin.com/web/Itineraires?strStartLocid='.$this->getHash($from).'&strDestLocid='.$this->getHash($to).'">Click here to get route from '.ucwords($from).' to '.ucwords($to).'</a>';
}
public function getDistance($from, $to){
$a = $this->getHash($from);
$b = $this->getHash($to);
$html = $this->curl("http://www.viamichelin.com/web/Itineraires?strStartLocid=$a&strDestLocid=$b");
preg_match('#<span id="idResumeDistanceTotal">(.*?) km</span>#is', $html, $bingo);
return intval($bingo[1]);
}
public function getMap($from, $to){
$a = $this->getHash($from);
$b = $this->getHash($to);
$html = $this->curl("http://www.viamichelin.com/web/Itineraires?strStartLocid=$a&strDestLocid=$b");
preg_match('#"http://m1.viamichelin.com/mapsgene/dm/(.*?)"#is', $html, $bingo);
return "http://m1.viamichelin.com/mapsgene/dm/".$bingo[1];
}
private function getHash($city){
$data = $this->loadData($city);
preg_match('#gf : \"(.*?)\"#is', $data, $bingo);
if(!empty($bingo[1])) return $bingo[1];
}
function getLL($city){
$data = $this->loadData($city);
preg_match('#\{lon : (.*?), lat : (.*?)\}#is', $data, $bingo);
unset($bingo[0]);
return $bingo;
}
private function loadData($city){
$city = urlencode($city);
return $this->curl("http://www.viamichelin.com/vmw2/maf/dyn/controller/jseLocationFinder?strMerged=$city");
}
private function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
return curl_exec($ch);
curl_close ($ch);
}
}
PHP kôd:
$vm = new VM;
echo $vm->getDistance("beograd", "novi sad"); // 87
echo $vm->getMap("beograd", "novi sad"); // http://m1.viamichelin.com/mapsgene/dm/04LxfmB-n07biSPLE9YsjooDQn0fm2it7Bzh9tJi6BjxfebObLcqimOb9R-ZD5HiBV-bF3mwh4U4Ox4zTND4pQhwAjvr=Sx2HOJQ0piWtnDCMU5qMx3URFSRhQ83HRBQSJJ5vlHwmTxBWCsq=0Z-LoqvF2JQoqylZ-LzqyVU-Mzqy0I-9zq=U8o8zq=F5oIzcpFSmrMfg
Funkcija getDistance vraća
87, što je stvarni broj kilometara, a getMap vraća source od mape, tipa...
Cheers.