Tag Archives: W3C Geo

An exemple of use of the web service

One simple exemple with two uses of geo:truc as a web service.

First we create a very simple PHP function calling the web service, with its first parameter the location we want to get the coordinates, and the second the format in which we want them; and then we invoke the function first for geotagging our web page with META tags in the header section, then we call it again for georeferencing the place we want to write about, and why not, having it as a microformat.

<?php
function getGeoTag ($location, $format) {
$url = “http://www.geotruc.net/gt.php”;
$parameters = “?q=”.urlencode($location).”&format=”.$format;

return file_get_contents($url.$parameters);
}
?><html>
<head>
<!– First call of getGeoTag //–>

<?php echo getGeoTag (“New York, USA”, “html”); ?>
<title>Test geotag</title>
</head>
<body>
<!– Second call of getGeoTag //–>
Gergovie (<?php echo getGeoTag (“Gergovie, France”, “geo”);?>) is a place for winners!
</body>
</html>

As shown with this simple example, building applications using geo:truc as a web service isn’t difficult.

geo:truc as a web service

It is now possible to use geo:truc as a web service.
It is build around Google’s geocoder, and send results in the desired format.

Its use is (hopefully) simple:

  • the URL is: http://www.geotruc.net/gt.php
  • the first parameter is called q (how original!) and it’s where you write the location you want to find
  • the second one is format for getting the result in the format you want

For instance, if you want to know where is Gergovie located, according to Google Maps, and get the result as geoRSS, you write like this:
http://www.geotruc.net/gt.php?q=Gergovie, France&format=georss

Available formats are:

  • machine: for getting result as machine (triple) tags
  • geo: for result as geo (microformat)
  • geojson: result as geoJSON
  • georss: result as geoRSS simple
  • gml: result as geoRSS GML
  • html: result as HTML meta tag
  • kml: result as kml
  • w3cgeo: result as w3cgeo

Have fun :-)