<?php
$nominatimUrl = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q=';
$from = urlencode( "The London Eye, London" );
$to = urlencode( "St Paul's Cathedral, City of London" );
$fromLL = json_decode( file_get_contents( "{$nominatimUrl}{$from}" ) );
$toLL = json_decode( file_get_contents( "{$nominatimUrl}{$to}" ) );
$osrmUrl = 'http://router.project-osrm.org/viaroute?instructions=true';
$osrmUrl .= sprintf( "&loc=%.4f,%.4f", $fromLL[0]->lat, $fromLL[0]->lon );
$osrmUrl .= sprintf( "&loc=%.4f,%.4f", $toLL[0]->lat, $toLL[0]->lon );
$headers =
"User-Agent: Derick Rethans/Presentation/20131113 osm@derickrethans.nl\r\n" .
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" .
"Accept-Encoding: gzip\r\n";
$opts = array( 'http' => array( 'header' => $headers ) );
$context = stream_context_create($opts);
var_dump( json_decode( gzdecode( file_get_contents( $osrmUrl, false, $context ) ) ) );
?>