Search Flickr Photos based on Time and Geolocation

Just the other day I was working on a hack project at work where we wanted to pull up geotagged photos of an event purely based on a geo and time filter. I couldn’t find any good source code out there, so I thought I would post this. It uses phpFlickr for the Flickr API calls.

Please feel free to post any comments / suggestions

<style>
label {display:block}
</style>
<form action="index.php">
<h4>Bounding Box</h4>
<label>Bottom Left - Latitude</label>
<input type="text" id="bl_lat"/>
<label>Bottom Left - Longitude</label>
<input type="text" id="bl_lon"/>
<label>Top Right - Latitude</label>
<input type="text" id="tr_lat"/>
<label>Top Right - Longitude</label>
<input type="text" id="tr_lon"/>
<h4>Date Range</h4>
<label>Start Date/Time (YYYY-MM-DD HH:MM:SS)</label>
<input type="text" id="date_start"/>
<label>End Date/Time (YYYY-MM-DD HH:MM:SS)</label>
<input type="text" id="date_end"/>
</form>

<?php

if (!$_REQUEST['bl_lat'] || !$_REQUEST['bl_lon'] || !$_REQUEST['tr_lat'] || !$_REQUEST['tr_lon'] || !$_REQUEST['date_start'] || !$_REQUEST['date_end']) {
  echo '<span style="color:red">All fields are required</span>';
}
else {
  require_once("phpFlickr.php");

  $key    = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  $secret = "XXXXXXXXXXXX";

  $f = new phpFlickr($key, $secret, true);

  $date['start'] = date("Y-m-d H:i:s", strtotime($_REQUEST['date_start']));
  $date['end'] = date("Y-m-d H:i:s", strtotime($_REQUEST['date_end']));
  print_r($date);
  echo '<br/>';

  $photos = $f->photos_search(array(
                            "min_taken_date"  => $date['start'],
                            "max_taken_date"  => $date['end'],
                            "sort"  => "interestingness-desc",
                            "bbox"  => $_REQUEST['bl_lon'].','.$_REQUEST['bl_lat'].','.$_REQUEST['tr_lon'].','.$_REQUEST['tr_lat'],
                            "extras"  => "date_taken,date_upload,geo,tags"
                            ));

  echo '<!--';
  print_r($photos);
  echo '-->';

  echo "count: ".count($photos['photo']).'<br/>';
  foreach($photos['photo'] as $photo) {
    $owner = $f->people_getInfo($photo['owner']);
    echo '<img src="http://farm'.$photo['farm'].'.static.flickr.com/'.$photo['server'].'/'.$photo['id'].'_'.$photo['secret'].'_m.jpg"/>';
  }
}
?>

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply