geocaches.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. require 'required.php';
  3. $okapi = "http://opencaching.us/okapi/";
  4. if (is_empty($VARS['lat']) || is_empty($VARS['long'])) {
  5. sendError("Missing information.", true);
  6. }
  7. if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['lat'])) {
  8. sendError("Latitude (lat) is in the wrong format.", true);
  9. }
  10. if (!preg_match('/-?[0-9]{1,3}\.[0-9]{3,}/', $VARS['long'])) {
  11. sendError("Longitude (long) is in the wrong format.", true);
  12. }
  13. $lat = $VARS['lat'];
  14. $long = $VARS['long'];
  15. $limit = 25;
  16. if (!is_empty($VARS['limit']) && is_numeric($VARS['limit'])) {
  17. $limit = intval($VARS['limit']);
  18. }
  19. $json = file_get_contents($okapi . "services/caches/search/nearest?center=" . $lat . "|" . $long . "&limit=" . $limit . "&consumer_key=" . GEOCACHE_KEY);
  20. if (!$json)
  21. sendError("Something went wrong, try again later.", true);
  22. $caches = json_decode($json)->results;
  23. $list = "";
  24. foreach ($caches as $val) {
  25. $list .= $val . "|";
  26. }
  27. echo file_get_contents($okapi . "services/caches/geocaches?consumer_key=" . GEOCACHE_KEY . "&cache_codes=" . rtrim($list, "|"));