Consuming GeoRSS Feeds with PHP

by dbaldwin

In some cases you want to pull data from your Foundation server to an existing web application written in PHP. This article will briefly cover using PHP and the Magpie RSS library to access your GeoRSS feed. We recommend downloading the attached zip file and extracting into a directory on your development server. This download has all the necessary files you’ll need to begin your GeoRSS integration. At the time of this post the latest Magpie RSS version is 0.61. After extracting your files go ahead and open georss.php. You should see the following:

<?
require_once('rss_fetch.inc');
$url = "http://demo.ublip.com/readings/last/1";
$rss = fetch_rss($url);

echo "<strong>" . $rss->channel['title'] . "</strong><br />";
foreach ($rss->items as $item) {
	$title = $item['title'];
	$description = $item['description'];
	$point = $item['georss']['point'];
	echo($title . "<br />" . $description . "<br />" . $point);
}
?>

You’ll want to change your URL to point to your Foundation server as well as specify the appropriate device id parameter (in this case it’s device id 1). Magpie makes it easy to pull data from the feed as you can see in the foreach loop. The georss:point node contains a latitude and longitude delimited by a space character. We’ll leave it to you to split the string and grab the appropriate values.  The only other thing you’ll need to change is lines 66 and 67 in the extlib/Snoopy.class.inc file. This contains the username/password to access your GeoRSS feed and are the same credentials as your web login.

Now you should be able to see the location data displayed on your server by accessing http://www.youserver.com/georss.php. If you have any questions about this article or GeoRSS in general feel free to post them in our applications forum.