Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How can I filter by distance to a given geo location?

Posted on by 225

From the wiki here I should be able to filter on distance by 

$filter=geo.distance(location, geography'POINT(-122.131577 47.678581)') le 10

And I tried doing it with Javascript with no luck as JS has limits for the types of filters it can use. So I moved on to C#, but I'm stuck as I can see how the expression would look like. The documentation is a little poor, would be nice with an example but google ins't my friend. Anyways;

            var latitude = 25.075648;
            var longitude = 4.746094;

            QueryExpression qe = new QueryExpression()
            {
                EntityName = qi.EntityName,
                ColumnSet = new ColumnSet(qi.EntityColumns),
                TopCount = 5,
                Criteria =
                {
                    Filters =
                    {
                        new FilterExpression
                        {
                            FilterOperator = LogicalOperator.And,
                            Conditions =
                            {
                                // ???
                            }
                        }
                    }
                }
            };

The entity is msdyn_workorder and it has msdyn_latitude and msdyn_longitude. Has anyone created a filter in C# with distance and how did you do it?

*This post is locked for comments

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How can I filter by distance to a given geo location?

    Lars,

    I saw your reference and it has nothing common with WebApi of CRM. CRM's WebApi implementation doesn't support mentioned operators. So as I mentioned before the only approach available for you is approach I mentioned in my initial reply.

    Good luck.

  • _Lars_ Profile Picture
    _Lars_ 225 on at
    RE: How can I filter by distance to a given geo location?

    You made a plugin to Dynamics that does requests and filtering på latitude and longitude?

    From the wiki i referenced, docs.microsoft.com/.../odata-expression-syntax-for-azure-search, one could clearly make these filters. But what are the system requirements for this? Azure Search is mentioned, what is that vs on premise?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How can I filter by distance to a given geo location?

    Hello,

    I was doing similar functionality and you just can't build it using standard query.

    I was designing special action and plugin that handled message of that action. I'm afraid this is the only way for you.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans