Closed jmjoy closed 6 months ago
嘿,@jmjoy,又见面了!希望你今天心情不错 😜
在go-wechaty中,当OnMessage
接收到的Message
的Type
是MessageTypeLocation
时,获取经纬度信息的方法并不直接。根据提供的上下文,Message
结构体中并没有直接的方法或属性可以让你直接获取位置消息的经纬度。
在go-wechaty中,MessageTypeLocation
消息的位置信息通常会被封装在特定于位置消息的有效负载中。由于提供的代码中没有直接访问位置信息(如经纬度)的方法,你需要扩展Message
结构体的功能,或者使用底层的Puppet
接口来访问包含位置信息的原始消息数据。
如果wechaty-puppet
接口或者你正在使用的特定puppet支持位置消息,它可能会提供一个类似于MessageFile
、MessageContact
、MessageURL
或MessageMiniProgram
的方法来获取位置详情。你需要查看puppet的文档或源代码以找到这样的方法。
在没有直接方法的情况下,一种方法是在Message
结构体中实现一个新的方法,该方法使用GetPuppet()
方法来访问puppet的API,以获取包含MessageTypeLocation
消息的位置详情的原始消息数据。这种方法需要了解puppet的API以及它如何存储或提供位置数据的访问。
鉴于提供的上下文的限制,以下是你可能开始实现这样一个方法的假设示例,假设puppet的API有一个名为MessageLocation
的方法,该方法返回位置详情:
// ToLocation retrieves the location information from a location type message.
func (m *Message) ToLocation() (*LocationPayload, error) {
if m.Type() != schemas.MessageTypeLocation {
return nil, errors.New("message not a location type")
}
locationPayload, err := m.GetPuppet().MessageLocation(m.id)
if err != nil {
return nil, err
}
return locationPayload, nil
}
这个示例假设存在一个LocationPayload
结构体来保存位置数据,以及puppet接口中的一个MessageLocation
方法,这些在提供的上下文中都不存在。你需要根据你正在使用的puppet的实际能力和API来调整这种方法。
来源:
暂时还不支持 MessageTypeLocation 类型的消息处理, 不过我刚提了一个 pr:https://github.com/wechaty/go-wechaty/pull/162 去支持,还没来得及测试
已在 v0.4.12 版本支持
感谢大佬!
我看Text是空的,也没有ToLocation之类的方法,怎么能获取到Location的经纬度?