/// <summary> /// 获取解析结果 /// </summary> /// <returns></returns> public ReverseGeocoderResultModel GetGeocoderResult() { try { string str = RequestData.GetResponseStream(Url); ReverseGeocoderResultModel model = new ReverseGeocoderResultModel(); if (!string.IsNullOrEmpty(str)) { if (ParamModel != null) { if (ParamModel.output.ToString().ToLower() == "xml") { model = Serializer.FromXml <ReverseGeocoderResultModel>(str); } else { model = Serializer.FromJson <ReverseGeocoderResultModel>(str); } } } return(model); } catch (Exception ex) { throw ex; } }
/// <summary> /// 返回尽可能 精确的地址信息 /// </summary> /// <param name="model"></param> /// <returns></returns> private string GetAddress(ReverseGeocoderResultModel model) { string result = ""; if (model != null) { if (model.status == 0) { if (model.result != null) { if (!string.IsNullOrEmpty(model.result.formatted_address)) { return(model.result.formatted_address); } if (!string.IsNullOrEmpty(model.result.sematic_description)) { return(model.result.sematic_description); } if (!string.IsNullOrEmpty(model.result.business)) { return(model.result.business); } if (model.result.addressComponent != null) { if (!string.IsNullOrEmpty(model.result.addressComponent.district)) { return(model.result.addressComponent.district); } if (!string.IsNullOrEmpty(model.result.addressComponent.city)) { return(model.result.addressComponent.city); } if (!string.IsNullOrEmpty(model.result.addressComponent.province)) { return(model.result.addressComponent.province); } if (!string.IsNullOrEmpty(model.result.addressComponent.country)) { return(model.result.addressComponent.country); } } } } } return(result); }
/// <summary> /// 坐标取地址 /// </summary> /// <param name="location"></param> /// <returns></returns> public string Test(string location) { string _Address = ""; ReverseGeocoding gd = new ReverseGeocoding(new ReverseGeocodingParam() { ak = "", callback = "", coordtype = "wgs84ll", location = location, output = "json", pois = 0, sn = "" } ); ReverseGeocoderResultModel gdresult = gd.GetGeocoderResult(); _Address = GetAddress(gdresult); return(_Address + "<br/><br/>" + Serializer.ToJson(gdresult)); }
private string GetAddressByGPS(string gps) { if (gps.Contains("|")) { gps = string.Join(",", gps.Split("|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)); } string _Address = string.Empty; var gd = new ReverseGeocoding(new ReverseGeocodingParam() { ak = "", callback = "", coordtype = "", location = gps, output = "json", pois = 0, sn = "" }); ReverseGeocoderResultModel gdresult = gd.GetGeocoderResult(); _Address = GetAddress(gdresult); return(_Address); }