2020-03-18 11:41:13 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using LeanCloud.Storage;
|
|
|
|
|
|
|
|
|
|
namespace LeanCloud.Realtime {
|
2020-04-27 17:44:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 位置消息
|
|
|
|
|
/// </summary>
|
2020-03-18 11:41:13 +08:00
|
|
|
|
public class LCIMLocationMessage : LCIMTextMessage {
|
2020-04-27 17:44:14 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 位置
|
|
|
|
|
/// </summary>
|
2020-03-18 11:41:13 +08:00
|
|
|
|
public LCGeoPoint Location {
|
|
|
|
|
get; set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 16:21:29 +08:00
|
|
|
|
internal LCIMLocationMessage() {
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 11:41:13 +08:00
|
|
|
|
public LCIMLocationMessage(LCGeoPoint locaction) : base(null) {
|
|
|
|
|
Location = locaction;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 16:21:29 +08:00
|
|
|
|
internal override Dictionary<string, object> Encode() {
|
|
|
|
|
Dictionary<string, object> data = base.Encode();
|
|
|
|
|
Dictionary<string, object> locationData = new Dictionary<string, object> {
|
2020-04-27 17:44:14 +08:00
|
|
|
|
{ MessageDataLongitudeKey, Location.Longitude },
|
|
|
|
|
{ MessageDataLatitudeKey, Location.Latitude }
|
2020-03-18 11:41:13 +08:00
|
|
|
|
};
|
2020-04-27 17:44:14 +08:00
|
|
|
|
data[MessageLocationKey] = locationData;
|
2020-03-18 16:21:29 +08:00
|
|
|
|
return data;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
2020-03-18 16:21:29 +08:00
|
|
|
|
|
2020-04-27 17:44:14 +08:00
|
|
|
|
internal override void Decode(Dictionary<string, object> msgData) {
|
|
|
|
|
base.Decode(msgData);
|
|
|
|
|
if (msgData.TryGetValue(MessageLocationKey, out object val)) {
|
|
|
|
|
Dictionary<string, object> locationData = val as Dictionary<string, object>;
|
|
|
|
|
double latitude = 0, longitude = 0;
|
|
|
|
|
if (locationData.TryGetValue(MessageDataLatitudeKey, out object lat) &&
|
|
|
|
|
double.TryParse(lat as string, out double la)) {
|
|
|
|
|
latitude = la;
|
|
|
|
|
}
|
|
|
|
|
if (locationData.TryGetValue(MessageDataLongitudeKey, out object lon) &&
|
|
|
|
|
double.TryParse(lon as string, out double lo)) {
|
|
|
|
|
longitude = lo;
|
|
|
|
|
}
|
|
|
|
|
Location = new LCGeoPoint(latitude, longitude);
|
|
|
|
|
}
|
2020-03-18 16:21:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-27 17:44:14 +08:00
|
|
|
|
public override int MessageType => LocationMessageType;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|