public void StoreInverseGeocoding(decimal latitude, decimal longtitude, string responseText) { InverseGeocodingEntity entity = new InverseGeocodingEntity(); entity.Latitude = latitude; entity.Longitude = longtitude; entity.CreatedDate = entity.LastUpdDate = DateTime.Now; try { if (this.ParseResponseText(responseText, ref entity) && this.CalculateCoordinate(latitude, longtitude, ref entity)) { // save to database. if (!DALFacade.InverseGeocoding.Exist(latitude, longtitude)) { DALFacade.InverseGeocoding.Insert(entity); } } ////if (this.ParseResponseText(responseText, ref entity) && this.CalculateCoordinate(latitude, longtitude, ref entity)) ////{ //// // save to database. //// if (DALFacade.InverseGeocoding.Exist(latitude, longtitude)) //// { //// DALFacade.InverseGeocoding.Update(entity); //// } //// else //// { //// DALFacade.InverseGeocoding.Insert(entity); //// } ////} } catch (Exception ex) { Logger.Error(ex); } }
public bool ParseResponseText(string responseText, ref InverseGeocodingEntity result) { try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(responseText); foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes) { switch (node.Name.ToLower()) { case "province": result.Province = node.InnerText; break; case "city": result.City = node.InnerText; break; case "dist": result.Dist = node.InnerText; break; case "area": result.Area = node.InnerText; break; case "town": result.Town = node.InnerText; break; case "village": result.Village = node.InnerText; break; case "poi": result.POIName = node.InnerText; break; case "poitype": result.POIType = node.InnerText; break; case "direction": result.POIDirection = node.InnerText; break; case "distance": float poiDistance = 0; if (float.TryParse(node.InnerText.Replace("米", ""), out poiDistance)) result.POIDistance = poiDistance; break; case "road": foreach (XmlNode roadNode in node.ChildNodes) { switch (roadNode.Name.ToLower()) { case "roadname": result.RoadName = roadNode.InnerText; break; case "roaddirection": result.RoadDirection = roadNode.InnerText; break; case "roadlevel": result.RoadLevel = roadNode.InnerText; break; case "roaddistance": float roadDistance; if (float.TryParse(roadNode.InnerText.Replace("米", ""), out roadDistance)) result.RoadDistance = roadDistance; break; default: break; } } break; default: break; } } return true; } catch //(Exception ex) { return false; } }
/// <summary> /// 根据经纬度计算出坐标值 /// </summary> public bool CalculateCoordinate(decimal latitude, decimal longtitude, ref InverseGeocodingEntity result) { result.RasterCode = RasterCoordinateUtility.CalculateCoordinate(latitude, longtitude); return true; }