mirror of
https://github.com/php/presentations.git
synced 2026-04-29 18:23:15 +02:00
33 lines
1.1 KiB
XML
33 lines
1.1 KiB
XML
<slide>
|
|
<title>Routing engine: OSRM</title>
|
|
|
|
<div effect="fade-out">
|
|
<image filename="osrm.png"/>
|
|
</div>
|
|
|
|
<div effect="fade-in">
|
|
<example result='1'><![CDATA[
|
|
<?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 ) ) ) );
|
|
?>]]></example>
|
|
</div>
|
|
</slide>
|