Created
February 7, 2013 17:55
-
-
Save marchawkins/4732784 to your computer and use it in GitHub Desktop.
Display your check-ins from foursquare on a map on your website with php.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// set default timezone (for date calcutations) | |
date_default_timezone_set('America/New_York'); | |
// setup array to hold checkins | |
$checkins = array(); | |
// enter your personal rss feed here (within the quotes); adjust the 'count=5' after the .rss to whatever number of checkins you want to display | |
$fsquareFeed = 'https://feeds.foursquare.com/history/YOURUNIQUEFOURSQUAREFEEDURL.rss?count=5'; | |
// read rss feed into a xml object | |
$xmlObject = simplexml_load_file($fsquareFeed); | |
$items = $xmlObject->channel; | |
$fsquareCheckins = $items->item; | |
// loop through xml object and fill array with checkins | |
foreach($fsquareCheckins as $item) { | |
$geopoint = explode(" ",$item->children('georss', true)->point); | |
$geo = array('lat'=>$geopoint[0], 'long'=>$geopoint[1]); | |
$description = $item->description; | |
$date = $item->pubDate; | |
$title = $item->title; | |
$myCheckin = array( | |
'title' => $title, | |
'desc' => $description, | |
'pubDate' => $date, | |
'geo' => $geo | |
); | |
array_push($checkins, $myCheckin); | |
} | |
// you now have an array called 'checkins' containing all the information from foursquare | |
?> | |
<html> | |
<head> | |
<title>foursquare checkins</title> | |
<style> | |
body {font-family: verdana,helvetica,sans-serif; font-size: 9pt;} | |
ol {padding-left: 20px;} | |
li {margin-bottom: 5px;} | |
</style> | |
</head> | |
<body> | |
<?php if(count($checkins)>0) { | |
// setup string to hold locations | |
$markers = ""; | |
// loop through checkins and build the 'markers' query variable | |
foreach($checkins as $checkin) { | |
// build pipe-separated list of locations for use in the google map | |
$markers .= $checkin['geo']['lat'].",".$checkin['geo']['long']."|"; | |
} | |
// trim the last pipe character | |
$markers = rtrim($markers,"|"); | |
?> | |
<h2>My latest foursquare check-ins</h2> | |
<div id="map"> | |
<?php /* embedded, static google map; api details: https://developers.google.com/maps/documentation/staticmaps/ */ ?> | |
<a href="http://maps.googleapis.com/maps/api/staticmap?size=600x400&maptype=roadmap&markers=color:blue%7C<?= $markers ?>&sensor=false" title="view a larger map"><img class="map" title="click to view big map" src="http://maps.googleapis.com/maps/api/staticmap?size=280x185&maptype=roadmap&markers=<?= $markers ?>&sensor=false" alt="latest foursquare check-in"/></a> | |
</div><!-- #map --> | |
<div id="list"> | |
<ol> | |
<?php foreach($checkins as $checkin) { | |
// display the formatted checkin time (called 'pubDate'); formatting info: http://php.net/manual/en/function.date.php | |
// then display the title of the location | |
?> | |
<li><?= date('D, M jS \a\t h:i a',strtotime($checkin['pubDate'])) ?> at <strong><?= $checkin['title']; ?></strong></li> | |
<?php } ?> | |
</ol> | |
</div><!-- #list --> | |
<div style="clear:both;"></div> | |
<?php } else { | |
/* if something goes wrong, display a message */ ?> | |
<p>Sorry, there was a problem. Try again later.</p> | |
<?php } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment