GSAK (Geocaching Swiss Army Knife)
Contents - Index

GetNear (function)

GetNear(sLatLon,sMeasurement,nNumber) : string

This new function will enable you to get a list of the nearest waypoints to a given coordinate. Your current filter is respected when you use this function. It has been added mainly for users that want to generate custom HTML pages and format their own "Nearest caches" summary, but it is not limited to this use.

sLatLon - This is the latitude and longitude pair that the distance to all the caches will be calculated from. It uses the generic GSAK coordinate input routine so the format is flexible.

sMeasurement - This is the required units for returning the distance. K = Kilometers, M = miles

nNumber - The number of caches to return

The function will return sNumber of lines which have the following format:


code = The waypoint code
description = The waypoint description
distance = The distance from the given coordinates (in the sMeasurement units)
bearing1 - The intercardinal bearing (N, NW, E, .....)
bearing2 - The true north bearing in degrees

The following macro is probably of little use but it does demonstrate how to find the 5 closest caches to your current cache:

$data = getnear($d_latitude + " " + $d_Longitude, "K", 5)
msgok msg=$data


Warning: The code has been fully optimized for speed, but the nature of this function means that it can be time consuming on large databases. To calculate the nearest waypoints, this function must calculate all the distances to all the caches to determine which are the nn nearest.

For example, on a test database of 10,000 caches this function takes 0.5 seconds for me. Doesn't seem too bad, but if you were to iterate through the whole database to find the 5 closest caches to each cache this would take 5,000 seconds (1.4 hours!)

So if you need to iterate through a group of waypoints doing this calculation, try to keep the subset of waypoints to a minimum.

Alpha List         Category List
Copyright 2004-2016 CWE Computer Services  
Privacy Policy Contact