Пример #1
0
        ///// <summary>
        ///// test
        ///// </summary>
        ///// <param name="args"></param>
        //public  void main()
        //{
        //    double lat = 39.90403;
        //    double lon = 116.407526; //需要查询经纬度,目前指向的是BeiJing
        //    string hash = Geohash.Encode(lat, lon);
        //    int geohashLen = 6;
        //    /*获取中心点的geohash*/
        //    String geohash = hash.Substring(0, geohashLen);
        //    /*获取所有的矩形geohash, 一共是九个 ,包含中心点,打印顺序请参考图2*/
        //    String[] result = Geohash.getGeoHashExpand(geohash);
        //}

        /// <summary>
        /// 生成查询 geohash 九个格子 的sql语句
        /// </summary>
        /// <param name="geohashLen">长度,5位是十平方千米(长 宽 3.3km),6位是3.3平方千米(长 宽 1点多km)</param>
        /// <param name="lat">纬度</param>
        /// <param name="lng">经度</param>
        /// <param name="geoHashField">数据库存geohash的字段名</param>
        /// <returns></returns>
        public static String getsqlGeoHash(int geohashLen, string Latitude, string Longitude, string geoHashField)
        {
            double lat  = double.Parse(Latitude);
            double lon  = double.Parse(Longitude);
            string hash = Geohash.Encode(lat, lon);


            /*获取中心点的geohash*/
            String geohash = hash.Substring(0, geohashLen);

            /*获取所有的矩形geohash, 一共是九个 ,包含中心点,打印顺序请参方法*/
            String[] result = Geohash.getGeoHashExpand(geohash);
            string where = "( ";
            for (int i = 0; i < 9; i++)
            {
                if (i == 0)
                {
                    where += geoHashField + " like '" + result[i] + "%' ";
                }
                else
                {
                    where += " or " + geoHashField + " like '" + result[i] + "%' ";
                }
            }
            where += ") ";
            return(where);
        }
Пример #2
0
        private static void Main(string[] args)
        {
            const double testLat   = 40.7571397;
            const double testLong  = -73.9891705;
            const int    precision = 13;

            // Calculate hash with full precision
            string hash = Geohash.Encode(testLat, testLong, precision);

            // Print out the hash for a range of precision
            for (int i = 1; i <= precision; i++)
            {
                Debug.WriteLine("{0}, {1} {2}: {3}", testLat, testLong, i, Geohash.Encode(testLat, testLong, i));
            }

            // Print neighbours
            Debug.WriteLine("{0} \t: {1}", "T", Geohash.CalculateAdjacent(hash, Geohash.Direction.Top));
            Debug.WriteLine("{0} \t: {1}", "L", Geohash.CalculateAdjacent(hash, Geohash.Direction.Left));
            Debug.WriteLine("{0} \t: {1}", "R", Geohash.CalculateAdjacent(hash, Geohash.Direction.Right));
            Debug.WriteLine("{0} \t: {1}", "B", Geohash.CalculateAdjacent(hash, Geohash.Direction.Bottom));
        }