Hi Mark,
To expand a bit further on my above post: My understanding is the DISTANCE function uses a google API call and when AIM sends parameters to it the distance is returned. I think the reason you cant use the FIND and DISTANCE functions together is that as AIM searches through objects it would need to hit google with a DISTANCE request for each object it iterates over. I'm pretty sure you are restricted to just making a few requests per second with google and if you hit it with lots of requests very quickly it just returns an error. I could be wrong, that's just a guess. It would be good if I was wrong altogether and the FIND and DISTANCE functions could be used together.
You got me thinking about how I managed to accomplish what you are trying to do. I've taken a look back at it and I'll do my best to try and explain what I did to make this work.
In essence I wanted to find clients that were close to where a workforce member was when that workforce member was out on the road and logged in on his mobile device.
I have the following business objects set up:
- Workforce (This is a system user)
- Property (This contains information about the clients premises)
The Property BO contains attributes that store the street address (postal address and postcode). The Property BO also contains attributes named 'Lat' and 'Lng'. I purchased a plugin from support that performs a ReverseGeocode Lookup with google. Using the plugin I am able to populate the Property.Lat and Propery.Lng attributes with the logitude and latitude returned by google based on the postal address and postcode stored in the Property BO. This is done via a process when a record of the 'Property' type is created.
The Workforce BO contains an attribute that stores the users current position, as co-ordinates, that were obtained during login (I'm not using V7 yet so I only get to capture their position at login). These co-ordinates are then broken down further to separate the latitude part from the longitude part. The Workforce BO also contains 4 'search parameter' attributes: LastKnownLat_SearchUpper, LastKnownLat_SearchLower, LastKnownLng_SearchUpper, LastKnownLng_SearchLower. Each time the Workforce members current position changes the following rule is executed:
If Workforce.CurrentPosition WAS CHANGED Then
Workforce.LastKnownLat_SearchLower=Workforce.LastKnownLatitude-0.006
Workforce.LastKnownLat_SearchUpper=Workforce.LastKnownLatitude+0.006
Workforce.LastKnownLong_SearchLower=Workforce.LastKnownLongitude-0.006
Workforce.LastKnownLong_SearchUpper=Workforce.LastKnownLongitude+0.006
The above rule populates the search parameters by adding aproximatley 1 mile (or maybe its 1Km? I can't remember) that's the +0.006 and -0.006. This creates what I believe is called a bounding box. Effectively an area of the earths surface for which we can then use to search. A true bounding box is actually circular whereas I think my method creates a square. The maths is way beyond me to create an imaginary circle. I believe it is somehow possible to use some sort of function inside MySQL to create a bounding box but again this is way beyond me. Simple isn't beyond me which is why I went with this method - it's close enough for my needs.
I digress. Stay with me. If you've managed to understand what I'm rambling on about this far then you'll know that we now have the users current location and we also have an imaginary area of the earths surface so we can now run the following rule/process:
FIND Property WHERE Property.Lat BETWEEN LoggedInWorkforce.LastKnownLat_SearchLower AND LoggedInWorkforce.LastKnownLat_SearchUpper AND Property.Lng BETWEEN LoggedInWorkforce.LastKnownLong_SearchLower AND LoggedInWorkforce.LastKnownLong_SearchUpper
This returns all instances of property that are within about 1 mile (or maybe 1Km) of the users current position. Well kind of if you remember that we created a square instead of a circle!
Now although this seems to work great for me I'm sure that this isn't the greatest way of doing it. If anyone can come up with anything better I would love to try it.
Mark, I hope this might help your visitors find those entities.
Ben, with an extra couple of attributes in my BO's I can use the following process to show a workforce member how far they are away from a selected property:
LoggedInWorkforce.Distance=DISTANCE(ThisProperty.MapAddress,LoggedInWorkforce.LastKnownLatLong)*0.000621371192
DISPLAY MESSAGE 'The distance to this property is '+LoggedInSystemUser.Distance+' miles from your last known location.<br><br>This calculation is based on where the crow flies and not by road or another route.'