/// <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> /// WGS坐标转火星坐标(World Geodetic System ==> Mars Geodetic System) /// </summary> /// <param name="Latitude">纬度</param> /// <param name="Longitude">经度</param> /// <param name="mgLat">输出火星坐标:纬度</param> /// <param name="mgLon">输出火星坐标:经度</param> /// <returns></returns> public static int WGS2GCJ(float Latitude, float Longitude, out float mgLat, out float mgLon) { mgLat = Latitude; mgLon = Longitude; double lat, lng; WGSToGCJAPI.Transform((double)Latitude, (double)Longitude, out lat, out lng); mgLat = (float)lat; mgLon = (float)lng; return(0); }
public string GetAddressByGPS(float Latitude, float Longitude) { string Provname, CityName, AreaName, FullAddress; double mgLat, mgLon; WGSToGCJAPI.Transform((double)Latitude, (double)Longitude, out mgLat, out mgLon); int ret = GoogleMapAPI.latLngToChineseDistrict((float)mgLat, (float)mgLon, out Provname, out CityName, out AreaName, out FullAddress); if (ret == 0) { return(FullAddress); } return("faild!"); }