Additions:
Deletions:
Additions:
Deletions:
Additions:
- The KML∞ representation of the map
- The PHP code to manipulate the XML was heavily lifted from [http://devzone.zend.com/node/view/id/1302∞ Zend Developer Zone]
Blog References
Details of Components
KML File
Google Maps conveniently publishes the relevant KML file at a URL which is the same as the map URL with
&output=kml appended.
Web Page
XSL Stylesheet
Deletions:
Additions:
It's easy to use
Google Maps∞ to set up a customised route by adding placemarks at navigationally-significant locations (see
this example∞), and you can easily add instructions (including pictures) at each point (try clicking on one of the "map pins").
However in the real world, there is nothing to beat having a list of instructions that each person can print out. I didn't want to re-type everything into a separate document, so created a
web page∞ to extract the key information from Google Maps and present it as a
tabular list∞. Editing the data in Google Maps is immediately reflected in the web page.
- The [http://earth.google.com/kml/kml_tags_21.html|KML∞] representation of the map
- A PHP script to pull down the relevant KML file, manipulate it by application of an XSL stylesheet, and create the resulting web page
- The XSL stylesheet
Assumptions and Limitations
- Assumes that the order in which waypoints are added to the Google Map is the correct navigational order. (this could be a real pain if you later needed to add an intermediate point)
- URL transform to get KML file is hard-coded
- Assumes that the only placemarks on the map are navigational waypoints
References
Deletions:
It's easy to use
Google Maps∞ to set up a customised route by adding placemarks at navigationally-significant locations (see
| this example∞), and you can easily add instructions (including pictures) at each point (try clicking on one of the "map pins").
However in the real world, there is nothing to beat having a list of instructions that each person can print out. I didn't want to re-type everything into a separate document, so created a
page∞ to extract the key information from Google Maps and present it as a [
http://www.synesthesia.co.uk/data/sp2tm.php|tabular∞ list]. Editing the data in Google Maps is immediately reflected in the web page.
# The [
http://earth.google.com/kml/kml_tags_21.html|KML∞] representation of the map
# A PHP script to pull down the relevant KML file, manipulate it by application of an XSL stylesheet, and create the resulting web page
# The XSL stylesheet
!!Assumptions and Limitations
* Assumes that the order in which waypoints are added to the Google Map is the correct navigational order. (this could be a real pain if you later needed to add an intermediate point)
* URL transform to get KML file is hard-coded
* Assumes that the only placemarks on the map are navigational waypoints
!!References
* A lot of the insight on manipulating KML came from [
http://cse-mjmcl.cse.bris.ac.uk/blog/2005/07/26/1122414882406.html|Mark∞ Mclaren's Weblog]
* The PHP code to manipulate the XML was heavily lifted from [
http://devzone.zend.com/node/view/id/1302|Zend∞ Developer Zone]
Additions:
Summary
It's easy to use
Google Maps∞ to set up a customised route by adding placemarks at navigationally-significant locations (see
| this example∞), and you can easily add instructions (including pictures) at each point (try clicking on one of the "map pins").
However in the real world, there is nothing to beat having a list of instructions that each person can print out. I didn't want to re-type everything into a separate document, so created a
page∞ to extract the key information from Google Maps and present it as a [
http://www.synesthesia.co.uk/data/sp2tm.php|tabular∞ list]. Editing the data in Google Maps is immediately reflected in the web page.
@import url(
http://www.synesthesia.co.uk/data/route.css∞ );
<div id = "wrapper">
<div id="header"><p>From Saint Paul's to Tate Modern</p><p>Walking Route To The Gallery</p></div>
<div class="intro">
<div class="source">
<p> The most up-to-date version of this route sheet can be found at <a href="<?php echo $thispageurl; ?>"><?php echo $thispageurl; ?></a></p>
<p>An online map of this route can be seen <a href="<?php echo $mapurl; ?>">here</a></p>
</div>
</div>
<?php printdirections($mapurl . "&output=kml");?>
exit;
print "Cannot write to file ($xml)";
exit;
print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
print " variable, the \$result variable has the following contents\n<br>\n";
print "<pre>\n";
print $result;
print html_entity_decode($result);
print "</pre>\n";
print "Sorry, could transform the source";
print " the reason is that " . xslt_error($xh) .
print " and the error code is " . xslt_errno($xh);
will be embedded in a page that handles html head and body elements
-->
<div class = "waypoint-list">
</div>
<table>
<tr>
<td class="instruction">
<td class="description">
<xsl:value-of select="*[local-name()='description']" />
</td>
</tr>
</table>
Deletions:
!!Summary
It's easy to use [
http://maps.google.com/∞ Google Maps] to set up a customised route by adding placemarks at navigationally-significant locations (see [
http://maps.google.com/maps/ms?ie=UTF8&hl=en&z=16&om=1&msid=114870744536353390965.00000111ea7e65a3111ef&msa=0∞ | this example]), and you can easily add instructions (including pictures) at each point (try clicking on one of the "map pins").
However in the real world, there is nothing to beat having a list of instructions that each person can print out. I didn't want to re-type everything into a separate document, so created a [
http://www.synesthesia.co.uk/data/sp2tm.php|web∞ page] to extract the key information from Google Maps and present it as a [
http://www.synesthesia.co.uk/data/sp2tm.php|tabular∞ list]. Editing the data in Google Maps is immediately reflected in the web page.
@import url(
http://www.synesthesia.co.uk/data/route.css∞ );
<div id = "wrapper">
<div id="header"><p>From Saint Paul's to Tate Modern</p><p>Walking Route To The Gallery</p></div>
<div class="intro">
<div class="source">
<p> The most up-to-date version of this route sheet can be found at <a href="<?php echo $thispageurl; ?>"><?php echo $thispageurl; ?></a></p>
<p>An online map of this route can be seen <a href="<?php echo $mapurl; ?>">here</a></p>
</div>
</div>
<?php printdirections($mapurl . "&output=kml");?>
exit;
print "Cannot write to file ($xml)";
exit;
print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
print " variable, the \$result variable has the following contents\n<br>\n";
print "<pre>\n";
print $result;
print html_entity_decode($result);
print "</pre>\n";
print "Sorry, could transform the source";
print " the reason is that " . xslt_error($xh) .
print " and the error code is " . xslt_errno($xh);
will be embedded in a page that handles html head and body elements
-->
<div class = "waypoint-list">
</div>
<table>
<tr>
<td class="instruction">
<td class="description">
<xsl:value-of select="*[local-name()='description']" />
</td>
</tr>
</table>
The oldest known version of this page was edited on
2007-04-23 13:11:08 by JulianElve
[Imported from bliki 2007-06-12]
!!Summary
This mini-project came about because I had a need to give people route instructions for a party.
It's easy to use [
http://maps.google.com/∞ Google Maps] to set up a customised route by adding placemarks at navigationally-significant locations (see [
http://maps.google.com/maps/ms?ie=UTF8&hl=en&z=16&om=1&msid=114870744536353390965.00000111ea7e65a3111ef&msa=0∞ | this example]), and you can easily add instructions (including pictures) at each point (try clicking on one of the "map pins").
However in the real world, there is nothing to beat having a list of instructions that each person can print out. I didn't want to re-type everything into a separate document, so created a [
http://www.synesthesia.co.uk/data/sp2tm.php|web∞ page] to extract the key information from Google Maps and present it as a [
http://www.synesthesia.co.uk/data/sp2tm.php|tabular∞ list]. Editing the data in Google Maps is immediately reflected in the web page.
There are three key components which are described in more detail later in this page.
# The [
http://earth.google.com/kml/kml_tags_21.html|KML∞] representation of the map
# A PHP script to pull down the relevant KML file, manipulate it by application of an XSL stylesheet, and create the resulting web page
# The XSL stylesheet
!!Assumptions and Limitations
* Assumes that the order in which waypoints are added to the Google Map is the correct navigational order. (this could be a real pain if you later needed to add an intermediate point)
* URL transform to get KML file is hard-coded
* Assumes that the only placemarks on the map are navigational waypoints
!!References
* A lot of the insight on manipulating KML came from [
http://cse-mjmcl.cse.bris.ac.uk/blog/2005/07/26/1122414882406.html|Mark∞ Mclaren's Weblog]
* The PHP code to manipulate the XML was heavily lifted from [
http://devzone.zend.com/node/view/id/1302|Zend∞ Developer Zone]
!! Blog References
* [
http://www.synesthesia.co.uk/blog/archives/2007/04/23/extracting-route-instructions-from-google-maps/∞ |Extracting Route Instructions from Google Maps]
!!Details of Components
!KML File
Google Maps conveniently publishes the relvant KML file at a URL which is the same as the map URL with <code>"&output=kml"</code> appended.
!Web Page
<code>
<?php
/*
Copyright Julian Elve 2007
Released under Creative Commons Attribution-
NonCommercial-
ShareAlike licence (
http://creativecommons.org/licenses/by-nc-sa/2.5/deed.en_GB∞)
*/
$thispageurl = "
http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF']∞;
$mapurl = "
http://maps.google.co.uk/maps/ms?ie=UTF8&hl=en&z=15&ll=51.511627,-0.096087&spn=0.011137,0.040169&t=h&om=1&msid=114870744536353390965.00000111ea7e65a3111ef&msa=0"∞;
?>
<html>
<head>
<title>From Saint Paul's to Tate Modern</title>
<style type="text/css" media="screen">
@import url(
http://www.synesthesia.co.uk/data/route.css∞ );
</style>
<link rel="stylesheet" type="text/css" media="print" href="
http://www.synesthesia.co.uk/data/route-print.css∞" />
</head>
<body>
<div id = "wrapper">
<div id="header"><p>From Saint Paul's to Tate Modern</p><p>Walking Route To The Gallery</p></div>
<div class="intro">
<div class="source">
<p> The most up-to-date version of this route sheet can be found at <a href="<?php echo $thispageurl; ?>"><?php echo $thispageurl; ?></a></p>
<p>An online map of this route can be seen <a href="<?php echo $mapurl; ?>">here</a></p>
</div>
</div>
<?php printdirections($mapurl . "&output=kml");?>
</div> <!-- /wrapper -->
</body>
</html>
<?php
function printdirections($kmlurl){
$xml = 'imported.xml';
$xsl = 'route.xsl';
if (!$file = fopen($kmlurl,"r")) {
print "Cannot open remote URL ($kmlurl)";
exit;
}
while(!feof($file))
$temp .= fgets($file, 1024);
fclose($file);
if (!$file = fopen($xml,"w")){
print "Cannot open file ($xml)";
exit;
}
if (fwrite($file, $temp)
FALSE) {
print "Cannot write to file ($xml)";
exit;
}
fclose($file);
Allocate a new XSLT processor
$xh = xslt_create();
Process the document, returning the result into the $result variable
$result = xslt_process($xh, $xml, $xsl);
if ($result) {
print "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
print " variable, the \$result variable has the following contents\n<br>\n";
print "<pre>\n";
print $result;
print html_entity_decode($result);
print "</pre>\n";
}
else {
print "Sorry, could transform the source";
print " the reason is that " . xslt_error($xh) .
print " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
}
?>
</code>
!XSL Stylesheet
<code>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
<xsl:output method="html" version="4.0"
encoding="iso-8859-1"
omit-xml-declaration="yes"/>
<!-- this version of the stylesheet assumes that the output
will be embedded in a page that handles html head and body elements
-->
<xsl:template match="/">
<div class = "waypoint-list">
<!--we want all the placemarks that are not the route line-->
<xsl:apply-templates select="kml:kml/kml:Document/kml:Placemark[not(kml:
LineString)]"/>
</div>
</xsl:template>
<xsl:template match="kml:Placemark">
<div class="waypoint">
<table>
<tr>
<td class="instruction">
<!--<p><xsl:value-of select="namespace-uri()" /></p>-->
<!--<p><xsl:value-of select="name()" /></p>-->
<p><b><xsl:value-of select="*[local-name()='name']"/></b></p></td>
<td class="description">
<xsl:value-of select="*[local-name()='description']" />
</td>
</tr>
</table>
</div>
</xsl:template>
</xsl:stylesheet>
</code>
Cite as "Multiple Authors; Summary
. Synesthesia Wiki; Retrieved 5th Dec 2008 from http://www.synesthesia.co.uk/wikka/ExtractingRouteInstructionsFromGoogleMap"