NIMSDK-AOS  10.9.80
V2NIMMessageLocationAttachmentBuilder.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.v2.message.attachment.builder;
2 
4 import com.netease.nimlib.v2.message.impl.attachment.V2NIMMessageLocationAttachmentImpl;
5 
6 /**
7  * V2NIM消息位置附件构建器
8  * <p>
9  * 该类用于构建V2NIM消息中的位置附件。它遵循构建器模式,允许链式调用来设置位置信息。
10  */
12 
13  /**
14  * 纬度
15  */
16  private double latitude;
17  /**
18  * 经度
19  */
20  private double longitude;
21  /**
22  * 详细位置信息
23  */
24  private String address;
25 
26  /**
27  * 私有构造函数,防止直接实例化
28  */
30  }
31 
32  /**
33  * 设置纬度,范围在-90到90之间,超出范围的无效
34  *
35  * @param latitude 纬度值
36  * @return 当前构建器实例
37  */
39  // 纬度不在有效范围内,无效
40  if (latitude < -90 || latitude > 90) {
41  return this;
42  }
43  this.latitude = latitude;
44  return this;
45  }
46 
47  /**
48  * 设置经度,范围在-180到180之间,超出范围的无效
49  *
50  * @param longitude 经度值
51  * @return 当前构建器实例
52  */
54  // 经度不在有效范围内,无效
55  if (longitude < -180 || longitude > 180) {
56  return this;
57  }
58  this.longitude = longitude;
59  return this;
60  }
61 
62  /**
63  * 设置详细地址
64  *
65  * @param address 地址字符串
66  * @return 当前构建器实例
67  */
69  this.address = address;
70  return this;
71  }
72 
73  /**
74  * 创建一个新的构建器实例
75  *
76  * @return 新的V2NIMMessageLocationAttachmentBuilder实例
77  */
80  }
81 
82  /**
83  * 构建V2NIMMessageLocationAttachment实例
84  *
85  * @return 新的V2NIMMessageLocationAttachment实例
86  */
88  return new V2NIMMessageLocationAttachmentImpl(latitude, longitude, address);
89  }
90 }
V2NIMMessageLocationAttachmentBuilder withLongitude(double longitude)
设置经度,范围在-180到180之间,超出范围的无效
V2NIMMessageLocationAttachmentBuilder withLatitude(double latitude)
设置纬度,范围在-90到90之间,超出范围的无效
static V2NIMMessageLocationAttachmentBuilder builder()
创建一个新的构建器实例