-2

Possible Duplicate:
How to call user defined function in LINQ in my visual C# web service for my android application?

I am currently developing an application on Android that will make use of the user location. The database will keep all the user location by latitude and longitude. I know how to calculate the distance from two points and it is a bit complicated.

However, in my webservice written in visual C#, I can't write something like this:

from a in db.Location.Where(a => distanceBetweenTwoLocations(givenLat, givenLong, a.lat, a.longi)<500) select new {...}

because the linq wont let me call my own function. Can anyone suggest some way to achieve my goal? For simplicity, i want to find other users that is 500m around me. I have all the user locations in latitude and longitude in my database.

Community
  • 1
  • 1
Chleung49
  • 41
  • 7
  • Asking the same thing in another question is generally discouraged – Jack Mar 20 '12 at 15:44
  • I suggest you look at Brian Cooley's answer to your other question http://stackoverflow.com/questions/9789124/how-to-call-user-defined-function-in-linq-in-my-visual-c-sharp-web-service-for-m his bounding box is how I'd do this. – Dampsquid Mar 20 '12 at 15:46

2 Answers2

1

Have a look at Nerddinner. http://nerddinnerbook.s3.amazonaws.com/Part11.htm

(use distancebetween function)

Create the relevant functions in your db.

then call them in your c#

raklos
  • 28,027
  • 60
  • 183
  • 301
0

There is an answer already, although it is in miles (1609.344 meters) instead of 500, but the calculation used is likely to fit your bill. It is using SQL, not LINQ, but you can easily convert this to a LINQ expression, especially if you have a tool like LINQPad.

Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32