如何调用我的Visual C#中的Web服务中的LINQ用户自定义函数为我的Andr​​oid应用程序?我的、自定义、应用程序、函数

2023-09-07 09:04:46 作者:夹了逼海盗

我目前工作的,将根据距离获取其他用户的位置的应用程序。

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)  )) {...}

不过,我得到了以下错误:LINQ到实体无​​法识别的方法和这种方法不能被翻译成店前pression

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

我不知道该如何翻译成一家商店前pression而且,计算也需要数学库​​。

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

有没有办法,我能做些什么来让LINQ EX pression叫我自己函数的办法?

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?

推荐答案

我真的不知道LINQ,但假设你只能发送简单的约束查询,我将建立一个方法,基本上没有calDistance的逆 - 取一个坐标和距离,并转换成一个边界框以最小经度,最大经度,纬度最小和最大纬度

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.

像(使用Java这里):

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.

 
精彩推荐
图片推荐