public Result <List <SuggestionResult> > Search(string query, string city = "成都市") { var checkMap = CheckMapKey(); if (!checkMap.IsSuccess) { return(Result <List <SuggestionResult> > .InnerError(checkMap.ErrorMessage)); } IDictionary <string, string> querystringArrays = new Dictionary <string, string>(); querystringArrays.Add("ak", MapAk); querystringArrays.Add("output", OutputString); querystringArrays.Add("query", query); querystringArrays.Add("region", city); //querystringArrays.Add("timestamp", AksnCaculater.GetTimeStamp()); querystringArrays.Add("city_limit", "true"); //querystringArrays.Add("sn", AksnCaculater.CaculateAKSN(MapAk, MapSk, MapSuggestionUrl, querystringArrays)); var url = AksnCaculater.HttpBuildQuery(querystringArrays); var result = HttpRequestHelper.SendRequest(MapHost + "/place/v2/search" + "?" + url); if (!result.IsSuccess) { return(Result <List <SuggestionResult> > .LogicError(result.ErrorMessage)); } SuggestionModel suggestionModel = result.Data.JsonToObj <SuggestionModel>(); return(suggestionModel.Status == 0 ? Result <List <SuggestionResult> > .Success(suggestionModel.Results ?? new List <SuggestionResult>()) : Result <List <SuggestionResult> > .LogicError(suggestionModel.Message)); }
/// <summary> /// 地理编码查询 /// </summary> /// <param name="address">检索地址</param> /// <param name="city">城市</param> /// <returns></returns> public Result <GeocoderResult> GetGeocoder(string address, string city = "北京市") { var checkMap = CheckMapKey(); if (!checkMap.IsSuccess) { return(Result <GeocoderResult> .InnerError(checkMap.ErrorMessage)); } SortedDictionary <string, string> querystringArrays = new SortedDictionary <string, string> { { "ak", MapAk }, { "address", address }, { "City", city }, { "output", OutputString }, { "timestamp", AksnCaculater.GetTimeStamp() } }; querystringArrays.Add("sn", AksnCaculater.CaculateAKSN(MapAk, MapSk, MapGeocoderUrl, querystringArrays)); var url = MapHost + MapGeocoderUrl + "?" + AksnCaculater.HttpBuildQuery(querystringArrays); var result = HttpRequestHelper.SendRequest(url); if (!result.IsSuccess) { return(Result <GeocoderResult> .LogicError(result.ErrorMessage)); } GeocoderModel geocoderModel = result.Data.JsonToObj <GeocoderModel>(); return(geocoderModel.Status == 0 ? Result <GeocoderResult> .Success(geocoderModel.Result ?? new GeocoderResult()) : Result <GeocoderResult> .LogicError(geocoderModel.Message)); }
/// <summary> /// 逆地理编码服务 /// </summary> /// <param name="location">坐标地址</param> /// <returns></returns> public Result <ReverseGeocodingReuslt> GetGeocoder(string location) { var checkMap = CheckMapKey(); if (!checkMap.IsSuccess) { return(Result <ReverseGeocodingReuslt> .InnerError(checkMap.ErrorMessage)); } Dictionary <string, string> querystringArrays = new Dictionary <string, string> { { "ak", MapAk }, { "location", location }, { "output", OutputString }, { "timestamp", AksnCaculater.GetTimeStamp() } }; querystringArrays.Add("sn", AksnCaculater.CaculateAKSN(MapAk, MapSk, MapGeocoderUrl, querystringArrays)); var url = MapHost + MapGeocoderUrl + "?" + AksnCaculater.HttpBuildQuery(querystringArrays); var result = HttpRequestHelper.SendRequest(url); if (!result.IsSuccess) { return(Result <ReverseGeocodingReuslt> .LogicError(result.ErrorMessage)); } ReverseGeocoding reverseGeocoding = result.Data.JsonToObj <ReverseGeocoding>(); return(reverseGeocoding.Status == 0 ? Result <ReverseGeocodingReuslt> .Success(reverseGeocoding.Result ?? new ReverseGeocodingReuslt()) : Result <ReverseGeocodingReuslt> .LogicError(reverseGeocoding.Message)); }
/// <summary> /// 根据坐标获取驾车距离 /// </summary> /// <param name="origins">出发地标准坐标</param> /// <param name="destinations">目的地标准坐标</param> /// <returns></returns> public Result <MapDistance> GetDrivingDistance(string origins, string destinations) { var checkMap = CheckMapKey(); if (!checkMap.IsSuccess) { return(Result <MapDistance> .InnerError(checkMap.ErrorMessage)); } var querystringArrays = new Dictionary <string, string> { { "ak", MapAk }, { "output", OutputString }, { "timestamp", AksnCaculater.GetTimeStamp() }, { "origins", origins }, { "destinations", destinations }, { "tactics", "11" }//常规路线,即多数人常走的一条路线,不受路况影响,可用于用车估价; }; querystringArrays.Add("sn", AksnCaculater.CaculateAKSN(MapAk, MapSk, MapDrivingUrl, querystringArrays)); var url = MapHost + MapDrivingUrl; var result = HttpRequestHelper.SendRequest(url + "?" + AksnCaculater.HttpBuildQuery(querystringArrays)); if (!result.IsSuccess) { return(Result <MapDistance> .LogicError(result.ErrorMessage)); } var drivingDistance = result.Data.JsonToObj <DrivingDistance>(); if (drivingDistance.Status == 0) { var firstOrDefault = drivingDistance.Result.FirstOrDefault(); return(Result <MapDistance> .Success(firstOrDefault != null?firstOrDefault.Distance : new MapDistance())); } else { return(Result <MapDistance> .LogicError(drivingDistance.Message)); } }