如何使用C#Microsoft Bot Builder Location显示位置

如何使用C#Microsoft Bot Builder Location显示位置,c#,botframework,C#,Botframework,我使用以下代码: using Microsoft.Bot.Builder.Dialogs; using Microsoft.Bot.Builder.Location; using Microsoft.Bot.Connector; using System; using System.Threading.Tasks; namespace LocationBotDemo.Dialogs { [Serializable] public class MainDialog : IDial

我使用以下代码:

using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Location;
using Microsoft.Bot.Connector;
using System;
using System.Threading.Tasks;

namespace LocationBotDemo.Dialogs
{
    [Serializable]
    public class MainDialog : IDialog<object>
    {
        public async Task StartAsync(IDialogContext context)
        {
            context.Wait(MessageReceivedStart);
        }
        public async Task MessageReceivedStart(IDialogContext context, IAwaitable<IMessageActivity> argument)
        {
            var message = await argument;

            var apiKey = Keys.bingMapsKey;
            var prompt = "Where should I ship your order? Type or say an address.";
            var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, LocationOptions.None, LocationRequiredFields.StreetAddress | LocationRequiredFields.PostalCode);
            context.Call(locationDialog, AfterLocationProvided);            
        }

        private async Task AfterLocationProvided(IDialogContext context, IAwaitable<object> result)
        {
            var message = await result;
            // loop back to beginning
            context.Wait(MessageReceivedStart);
        }
    }
}
在线上询问用户位置、街道和邮政编码。我不想那样。我想在不向用户询问任何内容的情况下显示位置

例如,我想展示“英国伦敦威斯敏斯特购物中心SW1A 2WH”,而不向用户提出任何要求。我该怎么做

要显示位置而不向用户询问任何内容吗

据我所知,并非所有通道都允许用户共享其位置,如果从特定通道发送的用户消息在消息实体中不包含位置信息,则您将无法通过消息实体在您的bot应用程序中检索用户的位置

和您一样,如果频道当前不支持共享其位置,您可以在bot应用程序中提示用户输入位置信息。我们可以使用来收集和验证用户所需的位置

此外,以下github问题讨论了类似的问题:从特定渠道获取用户位置,您可以查看链接以获取详细信息


    • 使用Bot框架无法做到这一点。您可以使用类似的API生成带有图钉的地图图像,然后将该图像作为或发送给用户。顺便说一下,这正是您在问题中提到的LocationDialog在引擎盖下使用的API:)

      我不想显示用户的位置。我想显示具体位置,如“英国伦敦SW1A 2WH威斯敏斯特购物中心”。
      显示具体位置,如“英国伦敦SW1A 2WH威斯敏斯特购物中心”
      正如我在回复中提到的,如果消息实体不包含位置信息,我们需要提示用户位置信息。如果你想在地图上显示位置,你可以调用一些地图API。
      var locationDialog = new LocationDialog(apiKey, message.ChannelId, prompt, LocationOptions.None, LocationRequiredFields.StreetAddress | LocationRequiredFields.PostalCode);