Bing Maps API-mapArea:此参数值超出范围

时间:2018-07-27 10:02:13

标签: botframework bing-maps bing-api azure-maps

我正在使用Bing Maps API使用BotFramework-Location NuGet包从某些位置生成图像。 (可以找到here的代码)

有时可以,但是有时由于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);
}

对此做出回应: Location HeroCards returned by BotFramework-Location NuGet Package.

未显示所有图像的原因是因为对Bing Maps API的Rest调用返回了以下内容:

  

mapArea:此参数值超出范围。

这是失败的图像uri之一(我删除了我的钥匙):

  

https://dev.virtualearth.net/REST/V1/Imagery/Map/Road?form=BTCTRL&mapArea=49.5737,5.53792,49.57348,5.53744&mapSize=500,280&pp=49.5737,5.53744;1;1&dpi=1&logo=always&key=NOT_REAL_12758FDLKJLDKJO8769KLJDLKJF

有人知道我在做什么错吗?

1 个答案:

答案 0 :(得分:1)

我想我理解您为什么会收到该错误。如您所说,我试图得到这张地图,并得到与您相同的结果:

  

mapArea:此参数值超出范围。

如果您查看提供的示例网址,则mapArea等于49.5737,5.53792,49.57348,5.53744

所以我只反转了定义此区域的2个点的坐标,将第一个具有较小纬度值的坐标放在首位,我得到了答复:

Image from maps

编辑:

正如您所评论的那样,此调用是在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项的格式没有限制。但是,如果您查看有关位置数据here的文档:

  

BoundingBox:包含位置的地理区域。边界框包含以度为单位的 SouthLatitude,WestLongitude,NorthLatitude和EastLongitude 值。

您可能知道,在代码中,SouthLatitude小于NorthLatitude(因为与厄瓜多尔相比,根据位置在代码中用正值和负值表示:43N为43,43S为-43)。所以问题似乎就在这里。

我进行了一次快速测试,以查看是否由于您之前(对GetLocationsByQueryAsync)的呼叫而导致错误,我无法重现这种情况。您能否分享与该问题有关的查询?