Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3610926
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:48:47+00:00 2026-05-18T21:48:47+00:00

I have users stored in a database that has latitude and longitude set on

  • 0

I have users stored in a database that has latitude and longitude set on them. I want to write a filter method in my service layer.

We are using ASP.NET MVC with the repository pattern. We will use entity framework with SQLServer for now. May switch to Azure or Amazon later.

My filter method looks like this:

    public static IQueryable<IPerson> InRadius(this IQueryable<IPerson> query, Coordinate center, double radius)
    {
        return (from u in query
                where
                    (Math.Pow(u.Location.Coordinate.Latitude - center.Latitude, 2) +
                     Math.Pow(u.Location.Coordinate.Longitude - center.Longitude, 2)) < Math.Pow(radius, 2)
                select u);
    }

Looking at this, something is wrong. This is a formula for normal trigonometry. This is assuming that radius is in the same measurement as the units that the Latitude and Longitude is in.

I have a few questions on this code:

  1. Because The service layer should have no idea of the ORM, will this query be executed on the database? Will Math.Pow(double,double) be passed to the database?
  2. If It cannot be done on the database, what would be the most efficient way to filter this data. I do not want to pull down all and then sort through them in my app.
  3. Geography question: Is there a way to convert a distance (whether miles, km) into the units that Latitude and Longitude uses? This if for the radius problem.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:48:48+00:00Added an answer on May 18, 2026 at 9:48 pm
    1. It’s probably mapped to POWER but you have to try it and find out to be sure.

    2. If it doesn’t translate to SQL, just change Math.Pow(someExpression, 2) to someExpression * someExpression. That will definitely be executed on the database.

    3. You can’t compute distances using longitude and latitude that way. Things are different on the surface of the Earth than in the Cartesian plane.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that has lots of data and is all neat, normalized
I have a website that has approx 1000 different strings in a mysql database
I have an asp.net web page that has a TinyMCE box. Users can format
I've got an old application that has user passwords stored in the database with
I have a sql database that stores some documents. A user can sign into
I have a website where users can upload their files; these are stored on
Let's say I have a fairly simple app that lets users store information on
I am working on a site that has a database schema like a tree.
I need to reformat my machine but I have so many user/passwords stored in
In my website, users have the possibility to store links. During typing the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.