botframework - Bing Maps API - mapArea:此参数值超出范围
问题描述
我正在使用 Bing Maps API 使用 BotFramework-Location NuGet 包从某些位置生成图像。(可以在这里找到哪些代码)
有时它可以工作,但有时由于 Rest 调用(由 BotFramework 调用,而不是我调用)中的错误而未加载图像
这是我的代码:
IGeoSpatialService geoService = new AzureMapsSpatialService(this.azureApiKey);
List < Location > concreteLocations = new List < Location > ();
foreach(String location in locations) {
LocationSet locationSet = await geoService.GetLocationsByQueryAsync(location);
concreteLocations.AddRange(locationSet ? .Locations);
}
// Filter out duplicates
var seenKeys = new HashSet < String > ();
var uniqueLocations = new List < Location > ();
foreach(Location location in concreteLocations) {
if (seenKeys.Add(location.Address.AddressLine)) {
uniqueLocations.Add(location);
}
}
concreteLocations = new List < Location > (uniqueLocations.Take(5));
if (concreteLocations.Count == 0) {
await context.PostAsync("No dealers found.");
context.Done(true);
} else {
var locationsCardReply = context.MakeMessage();
locationsCardReply.Attachments = new LocationCardBuilder(this.bingApiKey, new LocationResourceManager()).CreateHeroCards(concreteLocations).Select(card => card.ToAttachment()).ToList();
locationsCardReply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
await context.PostAsync(locationsCardReply);
}
未显示所有图像的原因是对 Bing 地图 API 的 Rest 调用返回以下内容:
mapArea:此参数值超出范围。
这是失败的图像uri之一(我删除了我的密钥):
有谁知道我做错了什么?
解决方案
我想我明白你为什么会出现这个错误。正如您所说,我试图获取此地图并得到与您相同的结果:
mapArea:此参数值超出范围。
如果您查看您提供的示例网址,mapArea
则等于49.5737,5.53792,49.57348,5.53744
所以我只是将定义该区域的2个点的坐标倒置,将纬度值较小的点放在第一位,我得到了答复:
编辑:
正如您所评论的,此调用是在BotBuilder-Location
代码内部进行的,而不是在您的代码中进行的。我看了看,这是生成地图的方法,在LocationCardBuilder
您正在实例化的类内部调用:
public string GetLocationMapImageUrl(Location location, int? index = null)
{
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
var point = location.Point;
if (point == null)
{
throw new ArgumentNullException(nameof(point));
}
if (location.BoundaryBox != null && location.BoundaryBox.Count >= 4)
{
return string.Format(
CultureInfo.InvariantCulture,
ImageUrlByBBox,
location.BoundaryBox[0],
location.BoundaryBox[1],
location.BoundaryBox[2],
location.BoundaryBox[3],
point.Coordinates[0],
point.Coordinates[1],
index,
this.apiKey);
}
else
{
return string.Format(
CultureInfo.InvariantCulture,
ImageUrlByPoint,
point.Coordinates[0],
point.Coordinates[1],
index,
apiKey);
}
}
可以看到,BoundaryBox 项的格式没有限制。但是,如果您在此处查看有关位置数据的文档:
BoundingBox:包含位置的地理区域。边界框包含以度为单位的SouthLatitude、WestLongitude、NorthLatitude 和 EastLongitude值。
您可能知道,在代码中,SouthLatitude 比 NorthLatitude 小(因为它在代码中用正值和负值表示,具体取决于与厄瓜多尔相比的位置:43N 是 43,43S 是 -43)。所以问题似乎就在这里。
我做了一个快速测试,看看我是否根据您之前 (to GetLocationsByQueryAsync
) 的调用得到了错误,但我无法重现这种情况。你能分享你所做的与这个问题相关的查询吗?
推荐阅读
- c# - MVC 核心集 IHostingEnvironment 到开发
- ios - 在 UITableView 之上向 UIView 添加阴影
- resize - OpenCv_Python - 将帧序列转换为视频
- php - 如何添加在选择表单php中选择的类
- java - jodaTime PeriodFormatter 格式不正确
- javascript - 为什么“koa-static”中间件不断返回 404?
- ios - 防止重复使用的单元格中的按钮再次出现
- git - Git 合并时会创建分支吗?
- php - PHP DOMXpath - 当有七个同名的类时从选定的HTML类中获取值
- sql-server-2014 - SQL Server 2014 偏移提取优化