C# Microsoft Bot框架地理定位

C# Microsoft Bot框架地理定位,c#,geolocation,botframework,chatbot,C#,Geolocation,Botframework,Chatbot,如何使用Bot框架获得用户地理坐标?我知道我必须使用实体,但不确定如何实际获取坐标,而不是定义它们。不幸的是,没有自动获取用户位置的方法,因为会侵犯用户隐私 但是,您始终可以请求用户的位置。取决于他们使用的聊天频道,他们可能会向您发送他们的位置(我在电报中测试过) 作为起点,您可能需要阅读 如何发送位置 示例代码: var reply = activity.CreateReply(); reply.ChannelData = new TelegramCustomMessage { Met

如何使用Bot框架获得用户地理坐标?我知道我必须使用实体,但不确定如何实际获取坐标,而不是定义它们。

不幸的是,没有自动获取用户位置的方法,因为会侵犯用户隐私

但是,您始终可以请求用户的位置。取决于他们使用的聊天频道,他们可能会向您发送他们的位置(我在电报中测试过)

作为起点,您可能需要阅读

如何发送位置 示例代码:

var reply = activity.CreateReply();
reply.ChannelData = new TelegramCustomMessage
{
    Method = "sendLocation",
    Parameters = new Parameters
    {
        ChatId = "your_chat_id",
        Latitute = 0,
        Longitute = 0
    }
};

public class TelegramCustomMessage
{
    [JsonProperty(PropertyName = "method")]
    public string Method { get; set; }
    [JsonProperty(PropertyName = "parameters")]
    public Parameters Parameters { get; set; }
}

public class Parameters
{
    [JsonProperty(PropertyName = "chat_id")]
    public string ChatId { get; set; }
    [JsonProperty(PropertyName = "latitute")]
    public float Latitute { get; set; }
    [JsonProperty(PropertyName = "longitute")]
    public float Longitute { get; set; }
}
if (entity.Type == "Place")
{
    Place place = entity.GetAs<Place>();
    GeoCoordinates geoCoord = place.Geo.ToObject<GeoCoordinates>();
    // geoCoord object will contains Longtitude & Latitude
}  

如何从活动中提取地理位置 示例代码:

var reply = activity.CreateReply();
reply.ChannelData = new TelegramCustomMessage
{
    Method = "sendLocation",
    Parameters = new Parameters
    {
        ChatId = "your_chat_id",
        Latitute = 0,
        Longitute = 0
    }
};

public class TelegramCustomMessage
{
    [JsonProperty(PropertyName = "method")]
    public string Method { get; set; }
    [JsonProperty(PropertyName = "parameters")]
    public Parameters Parameters { get; set; }
}

public class Parameters
{
    [JsonProperty(PropertyName = "chat_id")]
    public string ChatId { get; set; }
    [JsonProperty(PropertyName = "latitute")]
    public float Latitute { get; set; }
    [JsonProperty(PropertyName = "longitute")]
    public float Longitute { get; set; }
}
if (entity.Type == "Place")
{
    Place place = entity.GetAs<Place>();
    GeoCoordinates geoCoord = place.Geo.ToObject<GeoCoordinates>();
    // geoCoord object will contains Longtitude & Latitude
}  
if(entity.Type==“Place”)
{
Place=entity.GetAs();
地理坐标geoCoord=place.Geo.ToObject();
//geoCoord对象将包含经度和纬度
}  

团队刚刚添加了对定位服务框架的支持。超级有用:

你能在Node.js中放一个相同的片段吗?@PirateApp:对不起,我对NodeJS一无所知:)。Place entity也可以用于Facebook频道。然而,Facebook并没有提供一种请求用户位置的方法。唯一的方法就是通过短信询问。您确定可以使用
sendLocation
请求用户的位置,而不是向用户发送位置吗?你有一个有效的例子吗?@EugeneBerdnikov绝对没有,“sendLocation”不能用来请求用户的位置。但是,您可以使用它来提示用户,例如“这是您当前的位置吗?”或“这是您想要去的地方吗?”。对于请求用户的位置,您必须使用普通文本消息询问用户。