阿里云物联网的位置服务,并非彻底独立的功能。位置信息包含 二维、三维,位置数据来源于属性的上传。html
打开 数据分析 -> 空间数据可视化 -> 二维数据 -> 添加,为上面演示的设备添加位置,刷新时间为1秒。 在产品功能中,打开功能定义 ,在 标准功能 里,添加功能。
选择 其它类型 ,里面搜索 位置
,在出现的列表中选一个(前面那几个均可以)。
笔者选择的是:node
标识符:GeoLocation 适用类别:CuttingMachine
位置上传要设置的信息:git
注意注意,若是选择的标准属性跟上图的类型定义不同,须要手动修改。要把上面的位置属性按上图来改,有一个地方不一样,都会失败。 固然,也能够一开始就按图手动建立。json
上传位置数据,不须要作什么大操做,按照属性的上传方法上传便可。模型代码参考:服务器
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 { } } }
总体代码参考: 定义位置模型 -> 设置位置数据 -> 上传位置数据post
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 static void ToServer() { // 实例化模型 TestModel model = new TestModel(); // 设置属性值 // 经度 model.@params.GeoLocation.value.Longitude = 113.952981; // 纬度 model.@params.GeoLocation.value.Latitude = 22.539843; // 海拔 model.@params.GeoLocation.value.Altitude = 56; // 坐标系类型 model.@params.GeoLocation.value.CoordinateSystem = 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 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 { } } }
上面使用的是模拟位置数据,请实际状况设置位置数据。阿里云
打开阿里云物联网控制台 -> 数据分析 -> 空间数据可视化 -> 二维数据 -> 演示产品spa
会看到定位到了深圳阿里云大厦(高新园地铁站附近)~~~code