How do you find the center point of multiple GPS coordinates

Hello all!

I'm trying to find a way to find the center point of multiple GPS coordinates pulled from a photo's meta data. I've found some python examples, but was curious what the FileMaker community has come up with.

I'm also trying to exclude outliers. In case the photo was taken from across the street or multiple photos were taken while standing in the same spot. I've had less luck finding examples of this.

Thanks for the help!

1 Like

Google has an API that can calculate the center of a series of waypoints for you. But if you wanna do it all within FM, something like this could work. It finds the average of the min and max lat and lng and returns those coords.

It doesn't address the requirement to discard outliers, so you'd need to add more logic for that.

While ([
	~coords = "-10,1¶10,4¶2,5¶-12,4¶-12,-14" ;
	~minLat = 10000 ;
	~maxLat = -10000 ;
	~minLng = 10000 ;
	~maxLng = -10000 ;
	~i = 0 ;
	~count = ValueCount ( ~coords )
];
~i < ~count ;
[
	~i = ~i + 1 ;
	~row = Substitute ( GetValue ( ~coords ; ~i ) ; "," ; ¶ ) ;
	~lat = GetAsNumber ( GetValue ( ~row ; 1 ) ) ;
	~lng = GetAsNumber ( GetValue ( ~row ; 2 ) ) ;
	~minLat = If ( ~lat < ~minLat ; ~lat ; ~minLat ) ;
	~maxLat = If ( ~lat > ~maxLat ; ~lat ; ~maxLat ) ;
	~minLng = If ( ~lng < ~minLng ; ~lng ; ~minLng ) ;
	~maxLng = If ( ~lng > ~maxLng ; ~lng ; ~maxLng )
] ;
Average ( ~minLat ; ~maxLat ) & "," & Average ( ~minLng ; ~maxLng )
)

Thanks for the sample code. I'm a little worried about just using the min and max long/lat coords since the long/lats are a paired value and that might make excluding outliers a little trickier. Here's the python code I'm trying to rework if it helps.

Convert lat/lon (must be in radians) to Cartesian coordinates for each location.
X = cos(lat) * cos(lon)
Y = cos(lat) * sin(lon)
Z = sin(lat)

Compute average x, y and z coordinates.
x = (x1 + x2 + ... + xn) / n
y = (y1 + y2 + ... + yn) / n
z = (z1 + z2 + ... + zn) / n

Convert average x, y, z coordinate to latitude and longitude.
Lon = atan2(y, x)
Hyp = sqrt(x * x + y * y)
Lat = atan2(z, hyp)

My User's are working in fairly rural/remote areas, so I need to avoid anything that needs active internet connection (like google's api) and can be run on an iPad. They re-sync everything when they get back to the office

1 Like