最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用GPS經(jīng)緯度定位附近地點(diǎn)(某一點(diǎn)范圍內(nèi)查詢)

 更新時(shí)間:2013年12月30日 09:49:19   作者:  
目前的工作是需要手機(jī)查找附近N米以內(nèi)的商戶,致想法是已知一個(gè)中心點(diǎn),一個(gè)半徑,求圓包含于圓拋物線里所有的點(diǎn),經(jīng)緯度是一個(gè)點(diǎn),半徑是一個(gè)距離,不能直接加減,下面提供C#的解決方法

數(shù)據(jù)庫中記錄了商家在百度標(biāo)注的經(jīng)緯度(如:116.412007, 39.947545)

最初想法,以圓心點(diǎn)為中心點(diǎn),對(duì)半徑做循環(huán),半徑每增加一個(gè)像素(暫定1米)再對(duì)周長做循環(huán),到數(shù)據(jù)庫中查詢對(duì)應(yīng)點(diǎn)的商家(真是一個(gè)長時(shí)間的循環(huán)工作),上網(wǎng)百度類似的文章有了點(diǎn)眉目

大致想法是已知一個(gè)中心點(diǎn),一個(gè)半徑,求圓包含于圓拋物線里所有的點(diǎn),這樣的話就需要知道所要求的這個(gè)圓的對(duì)角線的頂點(diǎn),問題來了 經(jīng)緯度是一個(gè)點(diǎn),半徑是一個(gè)距離,不能直接加減

復(fù)制代碼 代碼如下:

/// <summary>
    /// 經(jīng)緯度坐標(biāo)
    /// </summary>   

  public class Degree
    {
        public Degree(double x, double y)
        {
            X = x;
            Y = y;
        }
        private double x;

        public double X
        {
            get { return x; }
            set { x = value; }
        }
        private double y;

        public double Y
        {
            get { return y; }
            set { y = value; }
        }
    }


    public class CoordDispose
    {
        private const double EARTH_RADIUS = 6378137.0;//地球半徑(米)

        /// <summary>
        /// 角度數(shù)轉(zhuǎn)換為弧度公式
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        private static double radians(double d)
        {
            return d * Math.PI / 180.0;
        }

        /// <summary>
        /// 弧度轉(zhuǎn)換為角度數(shù)公式
        /// </summary>
        /// <param name="d"></param>
        /// <returns></returns>
        private static double degrees(double d)
        {
            return d * (180 / Math.PI);
        }

        /// <summary>
        /// 計(jì)算兩個(gè)經(jīng)緯度之間的直接距離
        /// </summary>

        public static double GetDistance(Degree Degree1, Degree Degree2)
        {
            double radLat1 = radians(Degree1.X);
            double radLat2 = radians(Degree2.X);
            double a = radLat1 - radLat2;
            double b = radians(Degree1.Y) - radians(Degree2.Y);

            double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) +
             Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
            s = s * EARTH_RADIUS;
            s = Math.Round(s * 10000) / 10000;
            return s;
        }

        /// <summary>
        /// 計(jì)算兩個(gè)經(jīng)緯度之間的直接距離(google 算法)
        /// </summary>
        public static double GetDistanceGoogle(Degree Degree1, Degree Degree2)
        {
            double radLat1 = radians(Degree1.X);
            double radLng1 = radians(Degree1.Y);
            double radLat2 = radians(Degree2.X);
            double radLng2 = radians(Degree2.Y);

            double s = Math.Acos(Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Cos(radLng1 - radLng2) + Math.Sin(radLat1) * Math.Sin(radLat2));
            s = s * EARTH_RADIUS;
            s = Math.Round(s * 10000) / 10000;
            return s;
        }

        /// <summary>
        /// 以一個(gè)經(jīng)緯度為中心計(jì)算出四個(gè)頂點(diǎn)
        /// </summary>
        /// <param name="distance">半徑(米)</param>
        /// <returns></returns>
        public static Degree[] GetDegreeCoordinates(Degree Degree1, double distance)
        {
            double dlng = 2 * Math.Asin(Math.Sin(distance / (2 * EARTH_RADIUS)) / Math.Cos(Degree1.X));
            dlng = degrees(dlng);//一定轉(zhuǎn)換成角度數(shù)  原PHP文章這個(gè)地方說的不清楚根本不正確 后來lz又查了很多資料終于搞定了

            double dlat = distance / EARTH_RADIUS;
            dlat = degrees(dlat);//一定轉(zhuǎn)換成角度數(shù)

            return new Degree[] { new Degree(Math.Round(Degree1.X + dlat,6), Math.Round(Degree1.Y - dlng,6)),//left-top
                                  new Degree(Math.Round(Degree1.X - dlat,6), Math.Round(Degree1.Y - dlng,6)),//left-bottom
                                  new Degree(Math.Round(Degree1.X + dlat,6), Math.Round(Degree1.Y + dlng,6)),//right-top
                                  new Degree(Math.Round(Degree1.X - dlat,6), Math.Round(Degree1.Y + dlng,6)) //right-bottom
            };

        }
    }

測(cè)試方法:

復(fù)制代碼 代碼如下:

static void Main(string[] args)
        {
            double a = CoordDispose.GetDistance(new Degree(116.412007, 39.947545), new Degree(116.412924, 39.947918));//116.416984,39.944959
            double b = CoordDispose.GetDistanceGoogle(new Degree(116.412007, 39.947545), new Degree(116.412924, 39.947918));
            Degree[] dd = CoordDispose.GetDegreeCoordinates(new Degree(116.412007, 39.947545), 102);
            Console.WriteLine(a+" "+b);
            Console.WriteLine(dd[0].X + "," + dd[0].Y );
            Console.WriteLine(dd[3].X + "," + dd[3].Y);
            Console.ReadLine();
        }

試了很多次 誤差在1米左右

拿到圓的頂點(diǎn)就好辦了

數(shù)據(jù)庫要是sql 2008的可以直接進(jìn)行空間索引經(jīng)緯度字段,這樣應(yīng)該性能更好(沒有試過)

lz公司數(shù)據(jù)庫還老 2005的 這也沒關(guān)系,關(guān)鍵是經(jīng)緯度拆分計(jì)算,這個(gè)就不用說了 網(wǎng)上多的是 最后上個(gè)實(shí)現(xiàn)的sql語句

復(fù)制代碼 代碼如下:

SELECT id,zuobiao FROM dbo.zuobiao WHERE zuobiao<>'' AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',1)>116.41021 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',1)<116.413804 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',2)<39.949369 AND
dbo.Get_StrArrayStrOfIndex(zuobiao,',',2)>39.945721

相關(guān)文章

最新評(píng)論

霍邱县| 菏泽市| 商都县| 汽车| 镇雄县| 正镶白旗| 禄丰县| 朝阳区| 南乐县| 浪卡子县| 天镇县| 垦利县| 水城县| 鲁甸县| 砚山县| 宁陕县| 兴和县| 溧阳市| 洞头县| 吉首市| 鹰潭市| 南乐县| 会昌县| 津市市| 闽清县| 准格尔旗| 于田县| 眉山市| 公安县| 张家港市| 防城港市| 齐河县| 东源县| 闸北区| 霸州市| 江津市| 博爱县| 盐山县| 平顶山市| 黄骅市| 孝昌县|