【发布时间】:2016-08-30 04:15:15
【问题描述】:
如何使用 Bot Framework 获取用户的地理坐标?我知道我必须使用实体,但不确定如何实际获取坐标而不是定义它们。
【问题讨论】:
标签: c# geolocation botframework chatbot
如何使用 Bot Framework 获取用户的地理坐标?我知道我必须使用实体,但不确定如何实际获取坐标而不是定义它们。
【问题讨论】:
标签: c# geolocation botframework chatbot
很遗憾,没有自动方式获取用户的位置,因为这会侵犯用户隐私。
但是,您始终可以请求用户的位置。取决于他们使用的聊天频道,他们可能会向您发送他们的位置(我在 telegram 上测试过)
作为起点,您可能需要阅读有关
示例代码:
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; }
}
https://docs.botframework.com/en-us/csharp/builder/sdkreference/channels.html#customtelegrammessages
https://core.telegram.org/bots/api#sendlocation
示例代码:
if (entity.Type == "Place")
{
Place place = entity.GetAs<Place>();
GeoCoordinates geoCoord = place.Geo.ToObject<GeoCoordinates>();
// geoCoord object will contains Longtitude & Latitude
}
https://docs.botframework.com/en-us/csharp/builder/sdkreference/activities.html#places
【讨论】:
sendLocation 可用于请求用户的位置,而不是发送位置给用户吗?你有一个可行的例子吗?
团队刚刚添加了对定位服务框架的支持。超级有帮助:https://github.com/Microsoft/BotBuilder-Location
【讨论】: