$b[1];} /* Function that defines a couple of places, and echoes the one closest to user */ function closest($key) { require_once 'locationof.php'; $api=new LocationOf($key); $data=$api->get(); /* Define places here. [ [ string placename, double latitude, double longitude ] ] */ $places=array( array('the North Pole',90,'*'), array('the Equator',0,'*'), array('the South Pole',-90,'*') ); foreach($places as $k=>$v)$places[$k]=array($v[0],distance($data['last']['lat'],$data['last']['lon'],($v[1]==='*'?$data['last']['lat']:$v[1]),($v[2]==='*'?$data['last']['lon']:$v[2]))); usort($places,'compare'); echo $data['username'].' is now '.($places[0][1]<1?'at':($places[0][1]<5?'near':'closest to')).' '.$places[0][0].' ( '.sprintf('%.2f',$places[0][1]).' km )
'; } closest('demo'); /* Function that echoes the distance of user to the Central Station of Amsterdam, NL */ function amsterdam($key) { require_once 'locationof.php'; $api=new LocationOf($key); $data=$api->get(); /* Latitude and Longitude of Central Station in Amsterdam */ $place=array('lat'=>52.404,'lon'=>4.808); echo $data['username'].' is '.number_format(distance($data['last']['lat'],$data['last']['lon'],$place['lat'],$place['lon']),2).' km away from Amsterdam\'s central station.
'; } amsterdam('demo'); ?>