文档目录: <>
 * 说明 <https://www.cnblogs.com/whuanle/p/10994645.html> 
 * 1. 连接阿里云物联网 <https://www.cnblogs.com/whuanle/p/10994663.html> 
 * 2. IoT 客户端 <https://www.cnblogs.com/whuanle/p/10994673.html> 
 * 3. 订阅Topic与响应Topic <https://www.cnblogs.com/whuanle/p/10994686.html> 
 * 4. 设备上报属性 <https://www.cnblogs.com/whuanle/p/10994694.html> 
 * 4.1 上报位置信息 <https://www.cnblogs.com/whuanle/p/10994696.html> 
 * 5. 设置设备属性 <https://www.cnblogs.com/whuanle/p/10994701.html> 
 * 6. 设备事件上报 <https://www.cnblogs.com/whuanle/p/10994707.html> 
 * 7. 服务调用 <https://www.cnblogs.com/whuanle/p/10994708.html> 
 * 8. 委托事件 <https://www.cnblogs.com/whuanle/p/10994713.html> 
 * 9. 自定义委托事件方法
 <https://www.cnblogs.com/whuanle/p/10994720.html> 
 
阿里云物联网的位置服务,并不是完全独立的功能。位置信息包含 二维、三维,位置数据来源于属性的上传。
 
<https://gitee.com/whuanle/CZGL.AliIoTClient/wikis/4.1%20%E4%B8%8A%E6%8A%A5%E4%BD%8D%E7%BD%AE%E4%BF%A1%E6%81%AF?sort_id=1483467#1%E6%B7%BB%E5%8A%A0%E4%BA%8C%E7%BB%B4%E4%BD%8D%E7%BD%AE%E6%95%B0%E6%8D%AE>
1)添加二维位置数据
打开 数据分析 -> 空间数据可视化 -> 二维数据 -> 添加,为上面演示的设备添加位置,刷新时间为1秒。 在产品功能中,打开功能定义 ,在 标准功能 
里,添加功能。
选择 其它类型 ,里面搜索 位置 ,在出现的列表中选一个(前面那几个都可以)。
笔者选择的是:
标识符:GeoLocation 适用类别:CuttingMachine 
位置上传要设置的信息:
注意注意,如果选择的标准属性跟上图的类型定义不一样,需要手动修改。要把上面的位置属性按上图来改,有一个地方不同,都会失败。 当然,也可以一开始就按图手动创建。
 
<https://gitee.com/whuanle/CZGL.AliIoTClient/wikis/4.1%20%E4%B8%8A%E6%8A%A5%E4%BD%8D%E7%BD%AE%E4%BF%A1%E6%81%AF?sort_id=1483467#2%E5%9F%BA%E7%A1%80%E4%BB%A3%E7%A0%81>
2)基础代码
上传位置数据,不需要做什么大操作,按照属性的上传方法上传即可。模型代码参考:
public class TestModel { public string id { get { return 
DateTime.Now.Ticks.ToString(); }set { } } public string version { get { return 
"1.0"; }set { } } public Params @params { get; set; } public TestModel() { @
params =new Params(); } public class Params { public geoLocation GeoLocation { 
get;set; } public class geoLocation { public Value value { get; set; } public 
long time {get { return AliIoTClientJson.GetUnixTime(); } set { } } public 
geoLocation() { value = new Value(); } public class Value { public double 
Longitude {get; set; } public double Latitude { get; set; } public double 
Altitude {get; set; } public int CoordinateSystem { get; set; } } } public 
Params() { GeoLocation = new geoLocation(); } } public string method { get { 
return"thing.event.property.post"; } set { } } } 
整体代码参考: 定义位置模型 -> 设置位置数据 -> 上传位置数据
class Program { static AliIoTClientJson client; static void Main(string[] 
args) {// 创建客户端 client = new AliIoTClientJson(new DeviceOptions { ProductKey = 
"a1A6VVt72pD", DeviceName ="json", DeviceSecret = 
"7QrjTptQYCdepjbQvSoqkuygic2051zM", RegionId ="cn-shanghai" }); 
client.OpenPropertyDownPost();// 设置要订阅的Topic、运行接收内容的Topic string[] topics = new 
string[] { client.CombineHeadTopic("get") }; // 使用默认事件 
client.UseDefaultEventHandler();// 连接服务器 client.ConnectIoT(topics, null, 60); 
while (true) { ToServer(); Thread.Sleep(1000); } Console.ReadKey(); } public 
staticvoid ToServer() { // 实例化模型 TestModel model = new TestModel(); // 设置属性值 // 
经度 [email protected] = 113.952981; // 纬度 model.@
params.GeoLocation.value.Latitude = 22.539843; // 海拔 [email protected].
value.Altitude =56; // 坐标系类型 [email protected] = 
2;// 上传属性数据 client.Thing_Property_Post<TestModel>(model, false); } public class 
TestModel {public string id { get { return DateTime.Now.Ticks.ToString(); } set 
{ } }public string version { get { return "1.0"; } set { } } public Params @
params {get; set; } public TestModel() { @params = new Params(); } public class 
Params {public geoLocation GeoLocation { get; set; } public class geoLocation { 
public Valuevalue { get; set; } public long time { get { return 
AliIoTClientJson.GetUnixTime(); }set { } } public geoLocation() { value = new 
Value(); }public class Value { public double Longitude { get; set; } public 
double Latitude {get; set; } public double Altitude { get; set; } public int 
CoordinateSystem {get; set; } } } public Params() { GeoLocation = new 
geoLocation(); } }public string method { get { return 
"thing.event.property.post"; }set { } } } 
上面使用的是模拟位置数据,请实际情况设置位置数据。
打开阿里云物联网控制台 -> 数据分析 -> 空间数据可视化 -> 二维数据 -> 演示产品
会看到定位到了深圳阿里云大厦(高新园地铁站附近)~~~
热门工具 换一换
