本文整理汇总了C#中SearchCriteria.HasBounds方法的典型用法代码示例。如果您正苦于以下问题:C# SearchCriteria.HasBounds方法的具体用法?C# SearchCriteria.HasBounds怎么用?C# SearchCriteria.HasBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchCriteria
的用法示例。
在下文中一共展示了SearchCriteria.HasBounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
/// <summary>
/// get action result to search for localisation, for given criteria
/// </summary>
/// <param name="place">an address near where to find localisations</param>
/// <param name="offerType"></param>
/// <param name="types"></param>
/// <param name="features"></param>
/// <param name="maxCount"></param>
/// <returns></returns>
public virtual ActionResult Search(SearchCriteriaApi critariaApi)
{
//validate
if (critariaApi.IsEmpty())
return new ObjectResult<List<LocalisationJson>>(null, 400, "The \"place or name or latitude/longitude\" parameters must be filled");
//fill from parameter
eSearchType searchType = string.IsNullOrEmpty(critariaApi.name) ? eSearchType.ePerOffer : eSearchType.ePerName;
eOrderBy order = string.IsNullOrEmpty(critariaApi.name) ? (eOrderBy)critariaApi.orderBy : eOrderBy.Rating;
var criteria = new SearchCriteria { SearchType = searchType, OrderBy = order };
criteria.Boundary = critariaApi.boundary;
try
{
critariaApi.FillCriteria(ref criteria);
}
catch (Exception ex)
{
return new ObjectResult<List<LocalisationJson>>(null, 400, ex.Message);
}
//place
if (!string.IsNullOrEmpty(critariaApi.place))
{
criteria.Place = critariaApi.place;
float lat, lng;
_GeocodeService.GeoCode(critariaApi.place, out lat, out lng);
if (lat != 0)
critariaApi.latitude = lat;
if (lng != 0)
critariaApi.longitude = lng;
if (critariaApi.latitude == 0 || critariaApi.longitude == 0)
return new ObjectResult<List<LocalisationJson>>(null, 404, "The \"place\" can not be geocoded");
}
criteria.LocalisationData.Latitude = critariaApi.latitude;
criteria.LocalisationData.Longitude = critariaApi.longitude;
criteria.NorthEastLat = critariaApi.neLat;
criteria.NorthEastLng = critariaApi.neLng;
criteria.SouthWestLat = critariaApi.swLat;
criteria.SouthWestLng = critariaApi.swLng;
if (!string.IsNullOrEmpty(critariaApi.name))
criteria.LocalisationData.Name = critariaApi.name;
//search for matching localisations
var results = _SearchService.FillSearchResults(criteria);
//take the json
var list = results.List;
var neededLocs = (from item in list.Skip((critariaApi.page - 1) * MiscHelpers.Constants.PageSize).Take(MiscHelpers.ApiConstants.TakeCount) select item.GetJson(this, criteria));
var neededLocList = neededLocs.ToList();
double centerLat, centerLng;
if (criteria.HasBounds())
{
centerLat = (criteria.NorthEastLat + criteria.SouthWestLat) / 2;
centerLng = (criteria.NorthEastLng + criteria.SouthWestLng) / 2;
}
else
{
centerLat = criteria.LocalisationData.Latitude;
centerLng = criteria.LocalisationData.Longitude;
}
var toRet = new LocalisationsContainer
{
list = neededLocList,
maxCount = list.Count,
latitude = centerLat,
longitude = centerLng
};
return new ObjectResult<LocalisationsContainer>(toRet);
}