コード例 #1
0
        public async Task <Models.N.Location.PredictionsResult> GetPrediction(Models.N.Location.MapOptions options)
        {
            var service = new HttpRequestFactory();
            var url     = _configuration["GoogleMaps:Places:Url"]
                          .Replace("{key}", _configuration["GoogleMaps:Key"])
                          .Replace("{types}", _configuration["GoogleMaps:Places:Types"])
                          .Replace("{input}", options.Address.ToString());

            if (options.Location != null)
            {
                url += $"&location={options.Location.ToString()}&radius={_configuration["GoogleMaps:Places:Radius"]}&strictbounds";
            }


            var isError = false;

            try
            {
                return((await service.Get(url)).ContentAsType <PredictionsResult>());
            }
            catch (Exception)
            {
                isError = true;
                throw;
            }
            finally
            {
                this.Communicator_TraceHandler(this,
                                               new TraceEventArgs
                {
                    Description = "Get predictions.",
                    ElapsedTime = service.ElapsedTime,
                    ForceDebug  = false,
                    IsError     = isError,
                    Request     = service.Request,
                    Response    = service.Response,
                    URL         = url
                });
            }
        }
コード例 #2
0
 public string GetUrlMap(Models.N.Location.MapOptions options)
 {
     return($"{_configuration["GoogleMaps:UrlMap"].Replace("{key}", _configuration["GoogleMaps:Key"])}&{options.ToString()}");
 }