1

我的目的是获取地图边界,然后遍历我的集合并检查边界内的点。

所以第一步是获取地图边界:

LocationRect bounds = map.Bounds;
Location northwest = bounds.Northwest;
Location southeast = bounds.Southeast;

//Here I converts to DbGeography, because my server side works with it.
DbGeography DbNorthwest = new DbGeography()
{
    Geography = new DbGeographyWellKnownValue()
    {
        CoordinateSystemId = 4326,
        WellKnownText = GeoLocation.ConvertLocationToPoint(new GeocodeService.Location()
        {
            Latitude = northwest.Latitude,
            Longitude = northwest.Longitude
        })
    }
};

DbGeography DbSoutheast = new DbGeography()
{
    Geography = new DbGeographyWellKnownValue()
    {
        CoordinateSystemId = 4326,
        WellKnownText = GeoLocation.ConvertLocationToPoint(new GeocodeService.Location()
        {
            Latitude = southeast.Latitude,
            Longitude = southeast.Longitude
        })
    }
};

现在调用应该返回这两个点之间的所有对象的方法:

WcfClient client = new WcfClient();
var results = await client.GetEventsBetweenLocations(DbNorthwest, DbSoutheast);

现在我需要实现这个方法(位于实体框架上):我不知道怎么做?

public IQueryable<Event> GetEventsBetweenLocations(DbGeography first, DbGeography second)
{
    //How to check if the e.GeoLocation (which is DbGeography type) is between the two locations?
    return this.Context.Events.Where(e => e.GeoLocation ...?);
}

如果您能帮助我,我将不胜感激!!!:)

4

1 回答 1

4

一个可能的解决方案是找到由 NW 和 SE 点定义的边界框内的所有点,使用其 Well-known-text 表示构建:

DbGeography boundingBox = DbGeography.FromText(
        string.Format("POLYGON(({0} {1}, {3} {1}, {3} {2}, {0} {2}, {0} {1}))",
                first.Longitude,
                first.Latitude,
                second.Latitude,
                second.Longitude), 4326);

然后您可以找到与此特定边界框相交的“事件”:

return this.Context.Events.Where(e => e.GeoLocation.Intersects(boundingBox));
于 2013-09-01T15:11:06.947 回答