GeoBox ( latitude ; longitude ; radius )
Calculates latitude and longitude boundaries at radius of a location.
Average rating: 3.8 (53 votes) Log in to vote
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Use with your database of locations or addresses, each record having latitude and longitude geo data.
Given a longitude and latitude (ie. from a zip code db or geocode lookup) for your centerpoint and a radius in miles. This function will calculate boundary latitudes and longitudes, creating a box area for finding locations within the radius of the box's centerpoint. The result is delivered in a four member value list. (lat1¶lat2¶long1¶long2). Use FileMaker's GetValue function to retreive the values.
You can use the values for a Find:
criteria: Latitude= lat1 ... lat2 AND Longitude = long1 ... long2.
Or you can create a multipredicate relationship to define the range and pull in related records.
Things to consider:
Due to the fact that we are using a box instead of a circle, there is margin of error here but acceptable for most applications, such as retail locations, delivery information, etc.
These calculations are generally accepted formulas for approximate (close enough) results. There are other, albeit more complex formulas if pinpoint accuracy is required.
If your DB containing geo location data contains negative values (ie. negative longitudes for western hemisphere), it is best to just remove the negative signs and make sure that all data represents absolute values. This is easier than adjusting calculation results or find requests for occurances of negative values in your fields. This is valid as long as your radius calcs do not involve more than one quadrant. For example, the North American quadrant is all north latitudes and west longitudes.
vvv, GeoBox (35.0846 ; 106.6516 ; 20 )
Dec 26, 2014
Edward, Victoria, BC, CA — Sao Paulo, SP, BR
Dec 7, 2015
just added two more variables to your CF in order to adapt it to deal with negative values as well as miles and kilometers.
GeoBox( latitude ; longitude ; radius ; KmOrMiles ; roundVal )
"Km" for kilometers; any other value for miles
any numeric value (best if between 1~6) for roundVal
based on a CF written by Steve Murray
KmOrMiles = "Km";
radius * 1.609344;
Left ( latitude ; 1 ) = "-";
Left ( longitude ; 1 ) = "-";
stripLati = Filter ( latitude ; ".0123456789" );
stripLong = Filter ( longitude ; ".0123456789" );
lati01 = Round( stripLati - ( convRadius / 69.172 ) ; roundVal );
lati02 = Round( stripLati + ( convRadius / 69.172 ) ; roundVal );
long01 = Round( stripLong - ( convRadius / ( Cos( Radians( latitude ) ) * 69.172) ) ; roundVal );
long02 = Round( stripLong + ( convRadius / ( Cos( Radians( latitude ) ) * 69.172) ) ; roundVal )
signLati & lati01 & ¶ &
signLati & lati02 & ¶ &
signLong & long01 & ¶ &
signLong & long02
Aug 30, 2017
Best way to deal with this would be to change the middle section of the longer custom function to look like this:
Latitude < 0;
Longitude < 0;
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.