NIMSDK-AOS  9.16.0
LocationAttachment.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.msg.attachment;
2 
3 import com.netease.nimlib.util.JSONHelper;
4 
5 import org.json.JSONObject;
6 
10 public class LocationAttachment implements MsgAttachment {
11 
12  private double latitude;
13  private double longitude;
14  private String address;
15 
16  public LocationAttachment() {
17 
18  }
19 
20  public LocationAttachment(String attach) {
21  fromJson(attach);
22  }
27  public double getLatitude() {
28  return latitude;
29  }
30 
35  public void setLatitude(double latitude) {
36  this.latitude = latitude;
37  }
38 
43  public double getLongitude() {
44  return longitude;
45  }
46 
51  public void setLongitude(double longitude) {
52  this.longitude = longitude;
53  }
54 
59  public String getAddress() {
60  return address;
61  }
62 
67  public void setAddress(String address) {
68  this.address = address;
69  }
70 
71  private static final String KEY_LATITUDE = "lat";
72  private static final String KEY_LONGITUDE = "lng";
73  private static final String KEY_DESC = "title";
74 
75  private void fromJson(String attach) {
76  JSONObject json = JSONHelper.parse(attach);
77  latitude = JSONHelper.getDouble(json, KEY_LATITUDE);
78  longitude = JSONHelper.getDouble(json, KEY_LONGITUDE);
79  address = JSONHelper.getString(json, KEY_DESC);
80  }
81 
82  @Override
83  public String toJson(boolean send) {
84  JSONObject object = new JSONObject();
85  try {
86  object.put(KEY_LATITUDE, latitude);
87  object.put(KEY_LONGITUDE, longitude);
88  object.put(KEY_DESC, address);
89  } catch (Exception e) {
90  e.printStackTrace();
91  }
92 
93  return object.toString();
94  }
95 }
String getAddress()
获取地理位置描述信息
void setAddress(String address)
设置地理位置描述信息
String toJson(boolean send)
将消息附件序列化为字符串,存储到消息数据库或发送到服务器。