2013-09-01 3 views
1

Моя цель - получить границы карты, а затем перебрать мою коллекцию и проверить, какие точки находятся внутри границ.Bing Maps Как проверить, находится ли точка внутри границ карты?

Таким образом, первый шаг заключается в получении карты границы:

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

Возможное решение этого заключается в том, чтобы найти все точки внутри прямоугольника, определенной точками NW и SE, построен с использованием хорошо известной-текстовое представление:

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)); 
Смежные вопросы