Nearest Caches

This sample service displays nearest caches around user. User can view some info, navigate to caches or save them locally. Authentication is there against geocaching.com server. We want to be as much open as possible so we offer you a full PHP source code of service implementation.

Welcome message

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="en" lang="en">
	<head>
		<title>Nearest Caches</title>
	</head>
	<body class="serviceInfo">
		<div>
			<p class="description">Are you geocacher? This service is made for you! You can view nearest geocaches around you, view their terrain, difficulty etc.. Then you can save them locally or navigate to them! Geocaching was never easier!</p>
			<img src="http://services.locify.com/nearestCaches/logo.png" class="icon" alt="" />
			<a href="http://services.locify.com/nearestCaches/first.php" class="firstScreen">firstScreen</a>
		</div>
	</body>
</html>

First screen

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="en" lang="en">
  <head>
    <title>Show nearest caches
    </title>
  </head>
  <body class="form">
    <form action="http://services.locify.com/nearestCaches/nearest.php" method="post">
      <locify:variables>
			<locify:element name="lat" value="$lat" />
			<locify:element name="lon" value="$lon" />
		</locify:variables>
		<fieldset>
			<locify:where />
			<input type="hidden" name="lat" value="" />
			<input type="hidden" name="lon" value="" />
			<br />
			<label>Filter out finds:
          <select name="finds" locify:selected="1">
            <option value="1">Yes</option>
            <option value="0">No</option>
          </select>
         </label>
         <input type="submit" value="Show nearest" />
		</fieldset>
    </form>
  </body>
</html>

List of nearest caches

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="en" lang="en">
  <head>
    <title>Nearest caches
    </title>
  </head>
  <body class="list">
    <ul> <li>
      <a href="http://services.locify.com/nearestCaches/cache.php?guid=9cdc8370-cb96-448e-b785-c3b7bcb4fb6a" class="listItem">2.8km Run for the Border</a></li> <li>
      <a href="http://services.locify.com/nearestCaches/cache.php?guid=7f876965-aa93-4cef-abaa-ca0a6bf57aac" class="listItem">15.8km Conejossam's 2nd Puzzle Cache</a></li> <li>
      <a href="http://services.locify.com/nearestCaches/cache.php?guid=00c40878-0381-49d9-8b76-7d4e2076dc3c" class="listItem">17.2km All Things Gold</a></li> <li>
      <a href="http://services.locify.com/nearestCaches/cache.php?guid=20cbf638-6e8d-4f2a-a9fe-356ae9e3124d" class="listItem">17.7km Broyles Bridge Gaging Station</a></li> <li>
    </ul>
  </body>
</html>

Cache options

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="en" lang="en">
  <head>
    <title>
      <![CDATA[Run for the Border]]>
    </title>
  </head>
  <body class="list">
    <ul>
     <li><a href="http://services.locify.com/nearestCaches/navigate.php?guid=9cdc8370-cb96-448e-b785-c3b7bcb4fb6a" class="listItem">View &amp; navigate</a></li>
     <li><a href="http://services.locify.com/nearestCaches/cache.php?show=listing&amp;guid=9cdc8370-cb96-448e-b785-c3b7bcb4fb6a" class="listItem">Show listing</a></li>
     <li><a href="http://services.locify.com/nearestCaches/cache.php?show=hint&amp;guid=9cdc8370-cb96-448e-b785-c3b7bcb4fb6a" class="listItem">Show hint</a></li>
    </ul>
  </body>
</html>

Cache listing

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:locify="http://client.locify.com/locify_ns/1.0" xml:lang="en" lang="en">
  <head>
    <title>
      <![CDATA[Run for the Border]]>
    </title>
  </head>
  <body class="form">
    <form action="http://services.locify.com/nearestCaches/cache.php?guid=9cdc8370-cb96-448e-b785-c3b7bcb4fb6a" method="post">
      <fieldset>
        <input type="submit" value="Back" />
        <p>This is a fairly easy cache just off the side of the highway near the Colorado/New Mexico border. Park on the shoulder to access. The cache is a small to medium sized container that contains a log book, a pen, and the usual trading items. Note: There could be an occasional snake in the area, so watch your step.
        </p>
        <input type="submit" value="Back" />
        </fieldset>
    </form>
  </body>
</html>

View & Navigate (send user KML file)

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
  <Placemark>
    <name><![CDATA[Run for the Border]]></name>
    <description>
      <![CDATA[Type: Traditional Cache  Difficulty: 1.5  Terrain: 1.5  Size: Small  Author: Aardvark  Waypoint: GC1B0A1]]>
    </description>
    <Point>
      <coordinates>105.99453333333,36.975583333333</coordinates>
    </Point>
  </Placemark>
</kml>

PHP code

With this service, we provide you a complete source code of Locify service implemented in PHP. You can learn not only from view pages but also from service logic. Source code is well commented and you can run it right on your home server without any additional libraries etc. You can use this code for faster start of writing your own service.

The only thing you need to do to run this service on your server is to change constant with your server URL. You can find this constant in file functions.php:
At the beginning change
define('SERVICE_URL', 'http://services.locify.com/nearestCaches/');
to
define('SERVICE_URL', 'http://yourserver.com/path_to_nearest_caches/');

Download PHP code

Source code is under Creative Commons Attribution-Non-Commercial License

How does it look like

You need Flash Player and JavaScript to see video content.