Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Finding nearest unfound caches with OKAPI
<?php
/* Enter your OKAPI's URL here. */
$okapi_base_url = "https://opencaching.pl/okapi/";
/* Enter your Consumer Key here. */
$consumer_key = "YOUR_KEY_HERE";
/* Caches found by this user will be EXCLUDED from the result. */
$username = "USERNAME_HERE";
/* Your location. */
$lat = 54.3;
$lon = 22.3;
/* 1. Get the UUID of the user. */
$json = @file_get_contents(
$okapi_base_url."services/users/by_username".
"?username=".$username.
"&fields=uuid".
"&consumer_key=".$consumer_key
);
if (!$json)
die("ERROR! Check your consumer_key and/or username!\n");
$user_uuid = json_decode($json)->uuid;
print "Your UUID: ".$user_uuid."\n";
/* 2. Search for caches. */
$json = @file_get_contents(
$okapi_base_url."services/caches/search/nearest".
"?center=".$lat."|".$lon.
"&not_found_by=".$user_uuid.
"&limit=5".
"&consumer_key=".$consumer_key
);
if (!$json)
die("ERROR!");
$cache_codes = json_decode($json)->results;
/* Display them. */
print "Five nearest unfound caches: ";
print implode(", ", $cache_codes)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.