private (Location startLocation, Location endLocation) GetOriginAndDestination() { var client = ClientCreator.Create(); var startModel = new GeoCoderModel() { Address = "杭州市西湖区浙大路38号", }; var startRequest = new GeoCoderRequest(startModel); var startTask = client.ExecuteAsync(startRequest); var endModel = new GeoCoderModel() { Address = "浙江省杭州市拱墅区环城北路318号", }; var endRequest = new GeoCoderRequest(endModel); var endTask = client.ExecuteAsync(endRequest); Task.WaitAll(startTask, endTask); var startResponse = startTask.Result; var endResponse = endTask.Result; var startPoint = startResponse.Result.Location; var endPoint = endResponse.Result.Location; return(startPoint, endPoint); }
public void Test() { var baiduClient = ClientCreator.Create(); var model = new GeoCoderModel() { Address = "杭州市西湖区浙大路38号", }; var req = new GeoCoderRequest(model); var resp = baiduClient.Execute(req); resp.Status.ShouldBe(0); }
/// <summary> /// 根据地址获取高德的地址信息(包含坐标、城市省份地区地址、高德Poi),注意,本接口将通过网络访问高德服务器; /// 注意,只解析一个地址; /// </summary> /// <param name="client"></param> /// <param name="address"></param> /// <returns></returns> public static Geocode GetGeoResult(string address, string city = null) { var client = AMapConfig.GetClient(); address = address.Replace("(", "").Replace(")", "").Replace(" ", ""); var geoRequest = new GeoCoderRequest(new GeoCoderModel { Address = address, City = city }); var geoResponse = client.Execute(geoRequest); return(geoResponse.geocodes.First()); }
/// <summary> /// 根据地址获取百度的地址信息(包含坐标、城市省份地区地址、百度Poi),注意,本接口将通过网络访问百度服务器; /// </summary> /// <param name="client"></param> /// <param name="address"></param> /// <returns></returns> public static ReGeoDetailItem GetAddressInfo(BaiduMapClient client, string address) { address = address.Replace("(", "").Replace(")", "").Replace(" ", ""); var geoCoderModel = new GeoCoderModel { Address = address }; var req = new GeoCoderRequest(geoCoderModel); var res = client.Execute(req); if (res.Result == null || res.Result.Location == null) { return(null); //返回 null; } return(GetAddressInfo(client, res.Result.Location.Lng, res.Result.Location.Lat)); }