<?php
include 'flickr_api.inc';
include 'secrets.inc';
if(!isset($_POST['loc'])) $loc = 'Berkeley, CA';
$flickr = new Flickr($secrets);
$url = 'http://local.yahooapis.com/MapsService/V1/geocode';
$url .= '?appid=rlerdorf&location='.urlencode($loc);
$xml = simplexml_load_file($url)->Result;
$lat = (double)$xml->Latitude;
$lon = (double)$xml->Longitude;
$rad = (180.0/3.1415926);
$x = 4; $y = 4;
$dlat = ($x/6371) * $rad;
$lat1 = $lat - $dlat; $lat2 = $lat + $dlat;
$minlat = min($lat1,$lat2); $maxlat = max($lat1,$lat2);
$lon1 = $lon-(($y*cos($minlat)/6371) * $rad);
$lon2 = $lon+(($y*cos($maxlat)/6371) * $rad);
$minlon = min($lon1,$lon2); $maxlon = max($lon1,$lon2);
$params = array('bbox'=>"$minlon,$minlat,$maxlon,$maxlat",
'min_upload_date'=>time()-4*24*3600);
$photos = $flickr->photosSearch($params);
if(isset($photos['photos'])) foreach($photos['photos'] as $photo) {
$url = $flickr->getPhotoURL($photo);
echo '<img src="'.$url.'" height="75" width="75" />';
} else echo "No photos found";
?>
<form action="<?php echo htmlspecialchars($PHP_SELF)?>" method="POST">
Location: <input type=text name=loc size=60>
</form>