Brian Dunning's FileMaker Custom Functions

GeoBox ( latitude ; longitude ; radius )

Calculates latitude and longitude boundaries at radius of a location.

  Average rating: 3.8 (53 votes) Log in to vote

Steve Murray   Steve Murray
Steve Murray
http://www.nurse.tv

Share on Facebook Share on Twitter

  Sample input:
GeoBox (35.0846 ; 106.6516 ; 20 )
  Sample output:
34.7955
35.3737
106.2983
107.0049

  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.

Typical Use:
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.

 

Comments

vvv   vvv, GeoBox (35.0846 ; 106.6516 ; 20 )
Dec 26, 2014
ddd
 
Edward   Edward, Victoria, BC, CA — Sao Paulo, SP, BR
Dec 7, 2015
Steve,

hello.
just added two more variables to your CF in order to adapt it to deal with negative values as well as miles and kilometers.

best regards,

/*
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

Steve Murray
http://www.nurse.tv
*/

Let (
[

convRadius =
Case (

KmOrMiles = "Km";
radius * 1.609344;
radius
);

signLati =
Case (
Left ( latitude ; 1 ) = "-";
"-"
);

signLong =
Case (
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
)
 
Scott   Scott, Austin
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:

signLati =
Case (
Latitude < 0;
"-"
);

signLong =
Case (
Longitude < 0;
"-"
);
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.