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

Bing Maps API - mapArea: this parameter value is out of range

我正在使用 Bing 地图 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);
}

它回应了这个:

之所以没有显示所有图像,是因为 Rest 调用了 Bing 地图 API returns 这个:

mapArea: This parameter value is out of range.

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

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

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

我想我明白你为什么会收到那个错误。我尝试获取这张地图并得到与您相同的结果,如您所说:

mapArea: This parameter value is out of range.

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

所以我把定义这个区域的2个点的坐标倒过来,把纬度值小的放在最前面,得到回复:

编辑:

正如您评论的那样,此调用是在 BotBuilder-Location 代码中进行的,而不是在您的代码中进行的。我看了一下,这是生成地图的方法,在您正在实例化的 LocationCardBuilder class 中调用:

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: A geographic area that contains the location. A bounding box contains SouthLatitude, WestLongitude, NorthLatitude, and EastLongitude values in units of degrees.

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

我做了一个快速测试,看看我是否根据你之前的调用(对 GetLocationsByQueryAsync)得到了错误,我无法重现这个案例。你能分享你做的与这个问题相关的查询吗?