Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $string = file_get_contents("http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=***waypoint1***&wp.1=***waypoint2***&avoid=minimizeTolls&optmz=timeWithTraffic&routeAttributes=routeSummariesOnly&key=***apikey***");
- $json = json_decode($string, true);
- $json = $json[resourceSets][0][resources][0];
- $travelDuration = round($json["travelDuration"]/60);
- $travelDurationTraffic = round($json["travelDurationTraffic"]/60);
- $travelDistance = $json["travelDistance"];
- if ($travelDurationTraffic != 0) {
- sendCommand("Work_TimeNormal",$travelDuration);
- sendCommand("Work_TimeTraffic",$travelDurationTraffic);
- sendCommand("Work_KM",$travelDistance);
- }
- function sendCommand($item, $data) {
- $url = "http://127.0.0.1:8080/rest/items/" . $item;
- $options = array(
- 'http' => array(
- 'header' => "Content-type: text/plain\r\n",
- 'method' => 'POST',
- 'content' => (string)$data,
- ),
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement