Using the IGeoLocationService service, you can filter dynamic content items by their geographic location. The service shows where the items are located on a map.
Using this service, one could get all the locations within a circle, which is represented by point (latitude, longitude) and radius.
NOTE: The radius property is measured in kilometers.
The IGeoLocationService provides the following methods:
Definition: GetLocationsInCircle(double latitude, double longitude, double radius, DistanceSorting sorting = DistanceSorting.Asc, ItemFilter itemFilter = null)
Gets the locations of dynamic items within a specified circle. The method returns an IGeoLocation interface, which has all the information that is needed to interact with the geo location.
GetLocationsInCircle(double latitude, double longitude, double radius, DistanceSorting sorting = DistanceSorting.Asc, ItemFilter itemFilter = null)
Use the following code sample:
Definition: GetLocation (Guid itemId, string contentType, string customKey, string providerName)
Gets the geo location of the dynamic type if it has any, otherwise returns null. This method can be used when there is reference to the dynamic item. It returns an IGeoLocation item or null if there is no geo location for item with that id, contentType, customKey, and providerName. The custom key is a parameter, which is used to specify something unique for each item.
GetLocation (Guid itemId, string contentType, string customKey, string providerName)
Definition: UpdateLocation (Guid id, string contentType, string providerName, string customKey, Guid contentItemId, double latitude, double longitude)
Creates or updates an existing item depending on the parameter id. If you pass an empty GUID to this method, that means, that a new item will be created, but if you pass a non-empty GUID, the geo location that corresponds to that id will be updated in the database.
UpdateLocation (Guid id, string contentType, string providerName, string customKey, Guid contentItemId, double latitude, double longitude)
There are two ways to filter dynamic content items using the new Geo Location Service. The first one is to filter your dynamic module items, which have an Address field with enabled map and the second one is to filter by geo location points for your custom build types.
In the example below, we have a module with two dynamic content types. The first one represents restaurant objects and the second one – cinemas. First you need to publish the items in the system. This can be done either from the back-end interface or programmatically using the code reference for these types. Then you can use the IGeoLocationManager class to filter the items by distance from a specific point (using the FilterByGeoLocation method) and to sort them by distance (using the SortByDistance method).
Use the following code sample:
If a dynamic content type has more than one Address fields, filtering by a particular Address field can be done by specifying its field name as a propertyName when building the item filter.
NOTE: Filtering dynamic content items does not require registering geo location points (in the Geo Location Service), as this comes out-of-the-box.
If the CustomKey is not specified, then the items will be filtered by either of the fields.
The second option is to use the Geo Location Service directly to register your geo location points for your custom types. After you have registered the points, you can filter and sort your items by different criteria including: the type of the items, their provider and the key (name) of the field containing the geo location data.
Back To Top