Example #1
0
        public async Task <GooglePlaceAutoCompleteResult> GetPlaces(string text)
        {
            GooglePlaceAutoCompleteResult results = null;

            try
            {
                var query    = $"api/place/autocomplete/json?input={Uri.EscapeUriString(text)}&key={_googleMapsKey}";
                var response = await _httpClient.GetAsync(query);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (!string.IsNullOrWhiteSpace(json) && json != "ERROR")
                    {
                        results = await Task.Run(() =>
                                                 JsonConvert.DeserializeObject <GooglePlaceAutoCompleteResult>(json)
                                                 ).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception ex)
            {
                var message = ex;
            }

            return(results);
        }
Example #2
0
        public async Task <GooglePlaceAutoCompleteResult> GetPlaces(string text)
        {
            GooglePlaceAutoCompleteResult results = null;

            using (var httpClient = CreateClient())
            {
                var response = await httpClient.GetAsync($"api/place/autocomplete/json?input={Uri.EscapeUriString(text)}&key=AIzaSyByrk6O9m-zAuBRyXWIB_2btsb-kPiy7kA").ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (!string.IsNullOrWhiteSpace(json) && json != "ERROR")
                    {
                        //results = await Task.Run(() =>
                        //   JsonConvert.DeserializeObject<GooglePlaceAutoCompleteResult>(json)
                        //).ConfigureAwait(false);
                        var Req = JsonConvert.DeserializeObject <GooglePlaceAutoCompleteResult>
                                      (json);
                        results = Req;
                    }
                }
            }

            return(results);
        }
        public async Task <GooglePlaceAutoCompleteResult> GetPlaces(string text)
        {
            GooglePlaceAutoCompleteResult results = null;

            // Creates HTTPClient and uses it to call google maps api
            using (var httpClient = CreateClient())
            {
                var response = await httpClient
                               .GetAsync(
                    $"api/place/autocomplete/json?input={Uri.EscapeUriString(text)}&components=country:cz&types=(cities)&language=cs&key={_googleMapsKey}")
                               .ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (!string.IsNullOrWhiteSpace(json) && json != "ERROR")
                    {
                        results = await Task.Run(() =>
                                                 JsonConvert.DeserializeObject <GooglePlaceAutoCompleteResult>(json)
                                                 ).ConfigureAwait(false);
                    }
                }
            }

            return(results);
        }
        public async Task GetPlaces(string place)
        {
            GooglePlaceAutoCompleteResult result = await GoogleMapService.GetPlaces(place);

            if (result != null && result.Status == "OK")
            {
                Places = new ObservableCollection <GooglePlaceAutoCompletePrediction>(result.AutoCompletePlaces);
            }
        }
        public async Task <GooglePlaceAutoCompleteResult> GetPlaces(string text)
        {
            GooglePlaceAutoCompleteResult results = null;

            _apiService.BaseUri = ApiBaseAddress;
            var res = await _apiService.GetResponseAsync <GooglePlaceAutoCompleteResult>($"api/place/autocomplete/json?input={Uri.EscapeUriString(text)}&key={_googlePlaceKey}");

            results = res.Result;

            return(results);
        }
        public async Task <GooglePlaceAutoCompleteResult> GetPlaces(string text)
        {
            GooglePlaceAutoCompleteResult results = null;

            using (var httpClient = CreateClient())
            {
                var response = await httpClient.GetAsync($"api/place/autocomplete/json?input={Uri.EscapeUriString(text)}&key={EnvironmentConf.GoogleMapsApiKey}").ConfigureAwait(false);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (!string.IsNullOrWhiteSpace(json) && json != "ERROR")
                    {
                        results = await Task.Run(() =>
                                                 JsonConvert.DeserializeObject <GooglePlaceAutoCompleteResult>(json)
                                                 ).ConfigureAwait(false);
                    }
                }
            }
            return(results);
        }