Ejemplo n.º 1
0
        public void GetDistance()
        {
            var key = "geo_distance";

            // 删除已有
            _redis.Remove(key);

            var geo = new RedisGeo(_redis, key);

            // 普通添加
            geo.Add("北京", 116.404125, 39.900545);
            geo.Add("上海", 121.48789949, 31.24916171);

            // 计算两点距离
            var d = geo.GetDistance("北京", "上海");

            Assert.Equal(1066019.9908, d);
        }
Ejemplo n.º 2
0
        public void Test()
        {
            var key = "geo";

            // 删除已有
            _redis.Remove(key);

            var geo = new RedisGeo(_redis, key);

            // 普通添加
            geo.Add("Stone", 12.12, 34.34);

            // 批量添加
            var list = new List <GeoInfo>();

            for (var i = 0; i < 10; i++)
            {
                list.Add(new GeoInfo {
                    Name = "Test" + i, Longitude = i + 0.33, Latitude = i + 0.44
                });
            }
            geo.Add(list.ToArray());

            // 计算两点距离
            var d = geo.GetDistance("Test3", "Test5");

            Assert.Equal(314115.9636, d);

            // 获取多点坐标
            var gis = geo.GetPosition("Test2", "Test4", "Test7");

            Assert.Equal(3, gis.Length);

            Assert.Equal(233, (Int32)Math.Round(gis[0].Longitude * 100));
            Assert.Equal(244, (Int32)Math.Round(gis[0].Latitude * 100));

            Assert.Equal(433, (Int32)Math.Round(gis[1].Longitude * 100));
            Assert.Equal(444, (Int32)Math.Round(gis[1].Latitude * 100));

            Assert.Equal(733, (Int32)Math.Round(gis[2].Longitude * 100));
            Assert.Equal(744, (Int32)Math.Round(gis[2].Latitude * 100));
        }