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 7677851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:30:59+00:00 2026-05-31T17:30:59+00:00

I am currently working on an application that will retrieve other users’ locations based

  • 0

I am currently working on an application that will retrieve other users’ locations based on distance.

I have a database that store all the user location information in latitude and longitude.
Since the calculation of distance between these two pairs of latitude and longitude is quite complicated, I need a function to handle it.

from a in db.Location.Where(a => (calDistance(lat, longi, Double.Parse(a.latitude), Double.Parse(a.longitude)))<Math.Abs(distance)  )) {...}

However, I got the following error: LINQ to Entities does not recognize the method and this method cannot be translated into a store expression.

I don’t know how to translated it into a store expression and also, the calculation also need the math library.

Is there any method that i can do to let the LINQ expression call my own function?

Maybe there are other ways to achieve my goal, can anyone help?

  • 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-31T17:31:00+00:00Added an answer on May 31, 2026 at 5:31 pm

    I don’t really know LINQ, but assuming that you can only send simple constraints in the query, I would construct a method that basically does the inverse of calDistance – take a coordinate and a distance and convert it into a bounding box with a minimum longitude, maximum longitude, minimum latitude, and maximum latitude.

    You should be able to construct a simple query that will serve your purposes with those constraints.

    something like (using Java here):

    public double[] getCoordinateBounds(double distance, double longitude, double latitude) {
        double[] bounds = new double[4];
        bounds[0] = longitude - distanceToLongitudePoints * (distance);
        bounds[1] = longitude + distanceToLongitudePoints * (distance);
        bounds[2] = latitude - distanceToLatitudePoints * (distance);
        bounds[3] = latitude + distanceToLatitudePoints * (distance);
        return bounds;
    }
    

    Then you could construct a query.

    double[] bounds = getCoordinateBounds(distance, longi, lat);
    var nearbyUserLocations = from a in db.Location 
                             where longitude > bounds[0] and longitude < bounds[1]
                                and latitude > bounds[2] and latitude < bounds[3]
    

    This would give you a box of points rather than a radius of points, but it would be few enough points that you could then process them and throw out the ones outside your radius. Or you might decide that a box is good enough for your purposes.

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

Sidebar

Related Questions

We are currently working on an application that will use a WCF service. The
Am currently working on an application that requires users to submit posts and comments
I am currently working on an application that has different permissions/users for the local
A database application that I'm currently working on, stores all sorts of settings in
I am currently writing an application that will perform automation in Excel. I have
I'm currently working on an application that users a number of different views to
I am currently working on a application that will be implementing user customizable widgets
I am currently working on a VB.NET desktop application that uses .mdb (Access) database
I am currently working on a c# .NET desktop application that will be communicating
I have a web application that I am currently working on that uses a

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.