/// <summary> /// 根据当前经纬度获取所在的城市信息 /// </summary> /// <param name="AuthKey">授权码</param> /// <param name="Latitude">纬度</param> /// <param name="Longitude">经度</param> /// <returns></returns> public static OfficialCity GetCurrentOfficialCityByGPS(UserInfo User, float Latitude, float Longitude) { LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS:UserName="******",Latitude=" + Latitude.ToString() + ",Longitude=" + Longitude.ToString()); if (User == null) { return(null); } try { double mgLat, mgLon; //转火星坐标 WGSToGCJAPI.Transform((double)Latitude, (double)Longitude, out mgLat, out mgLon); Addr_OfficialCity city = null; ///默认根据Google地图API获取所在地 string Provname, CityName, AreaName, FullAddress; int ret = GoogleMapAPI.latLngToChineseDistrict((float)mgLat, (float)mgLon, out Provname, out CityName, out AreaName, out FullAddress); if (ret == 0) { //省 IList <Addr_OfficialCity> _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + Provname + "%' AND [LEVEL]=1"); if (_lists.Count > 0) { city = _lists[0]; //市 _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + CityName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=2"); if (_lists.Count > 0) { city = _lists[0]; //区、县 _lists = Addr_OfficialCityBLL.GetModelList("Name LIKE '" + AreaName + "%' AND SuperID=" + city.ID.ToString() + " AND [LEVEL]=3"); if (_lists.Count > 0) { city = _lists[0]; } } } } else { int cityid = GIS_OfficialCityGeoBLL.GetNearOfficialCityByLatLong(Latitude, Longitude); city = new Addr_OfficialCityBLL(cityid).Model; } return(new OfficialCity(city)); } catch (System.Exception err) { LogWriter.WriteLog("MemberService.GetCurrentOfficialCityByGPS Exception!UserName=" + User.UserName, err); return(null); } }
/// <summary> /// 计算经纬度的距离(米) /// </summary> /// <param name="latitude1">纬度1</param> /// <param name="longitude1">经度1</param> /// <param name="latitude2">纬度2</param> /// <param name="longitude2">经度2</param> /// <returns>返回两坐标间的距离(米)</returns> public static int DistanceByLatLong(double latitude1, double longitude1, double latitude2, double longitude2) { return((int)GIS_OfficialCityGeoBLL.DistanceByLatLong(latitude1, longitude1, latitude2, longitude2)); }