Пример #1
0
        static MapService()
        {
            try
            {
                BaiduAk = System.Configuration.ConfigurationSettings.AppSettings["BaiduAk"];
            }
            catch
            {
                BaiduAk = string.Empty;
            }

            /// <summary>
            /// 修正地址区域
            /// </summary>
            string AreaPoints1 = "22.56613,114.29093;22.58912,114.26713;22.58198,114.26093;22.56651,114.27473";
            //修正地址
            LocationInfo TempLocationInfo1 = new LocationInfo()
            {
                Area = "洪安路",
                City = "深圳市",
                Dist = "盐田区",
                Point = "深圳盐田国际集装箱码头",
                Province = "广东省",
                RoadName = "洪安路"
            };
            string AreaPoints2 = "22.67133,113.91344;22.67133,113.92008;22.66776,113.92008;22.66776,113.91344";
            LocationInfo TempLocationInfo2 = new LocationInfo()
            {
                Area = "二五三乡道",
                City = "深圳市",
                Dist = "宝安区",
                Point = "山城工业区",
                Province = "广东省",
                RoadName = "山城路"
            };
            string AreaPoints3 = "22.52039,113.92137;22.51914,113.9204;22.51843,113.92059;22.51806,113.92194;22.52011,113.92268;22.52041,113.92137";
            LocationInfo TempLocationInfo3 = new LocationInfo()
            {
                Area = "创业路",
                City = "深圳市",
                Dist = "南山区",
                Point = "海王大厦",
                Province = "广东省",
                RoadName = "创业路"
            };
            ltPToL.Add(new PointsToLocationInfo(AreaPoints1, TempLocationInfo1));
            ltPToL.Add(new PointsToLocationInfo(AreaPoints2, TempLocationInfo2));
            ltPToL.Add(new PointsToLocationInfo(AreaPoints3, TempLocationInfo3));
        }
Пример #2
0
 private bool InArea(string latitude, string longitude, out LocationInfo locationInfo)
 {
     locationInfo = null;
     try
     {
         decimal lat = Convert.ToDecimal(latitude);
         decimal lon = Convert.ToDecimal(longitude);
         return InArea(lat, lon, out locationInfo);
     }
     catch //(Exception ex)
     {
         return false;
     }
 }
Пример #3
0
 public PointsToLocationInfo(string points, LocationInfo locationInfo)
 {
     Points = points;
     LocationInfo = locationInfo;
 }
Пример #4
0
 private bool InArea(decimal lat, decimal lon, out LocationInfo locationInfo)
 {
     locationInfo = null;
     foreach (var item in ltPToL)
     {
         Polygon polygon = new Polygon(item.Points);
         double x = Convert.ToDouble(lat);
         double y = Convert.ToDouble(lon);
         Point point = new Point(x, y);
         bool isIn = Polygon.PointInPolygon(point, polygon);
         if (isIn)
         {
             locationInfo = item.LocationInfo;
             return true;
         }
     }
     return false;
 }
Пример #5
0
        public virtual LocationInfo InverseGeocoding(string latitude, string longitude)
        {

            if (!string.IsNullOrEmpty(BaiduAk))
            {
                LocationInfo location = new LocationInfo();
                var url = string.Format("http://api.map.baidu.com/geocoder/v2/?output=xml&coordtype=wgs84ll&location={0},{1},&ak={2}", latitude, longitude, BaiduAk);
                var xml = WebRequestHelper.GetResponseText(url, "application/x-www-form-urlencoded", 2000, "GET", Encoding.UTF8);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
                XmlElement root = doc.DocumentElement;
                XmlNode res = root.SelectSingleNode("result");
                location.Province = res.SelectSingleNode("addressComponent/province").InnerText;
                location.City = res.SelectSingleNode("addressComponent/city").InnerText;
                location.Dist = res.SelectSingleNode("addressComponent/district").InnerText;
                location.RoadName = res.SelectSingleNode("addressComponent/street").InnerText + " " + res.SelectSingleNode("sematic_description").InnerText;
                return location;
            }
            else 
            {
                string result = MapSearchService.InverseGeocoding(latitude, longitude);
                return DataResolver.GetGeocoding(result);
            
            }
        }