Exemplo n.º 1
0
        public async Task <ObservableCollection <IAutoCompleteResultModel> > GetAutoCompleteResponse(string input)
        {
            var currentLocation = _locationManager.LastKnownLocation;

            try
            {
                var request = new AutocompleteRequest
                {
                    Input    = input,
                    Location = new LatLng(currentLocation.Latitude, currentLocation.Longitude),
                    Radius   = 50000,
                    Language = "en|ru"
                };

                var result = await _placesService.GetAutocompleteResponseAsync(request);

                if (result?.Status != ServiceResponseStatus.Ok)
                {
                    return(null);
                }

                var addresses = new ObservableCollection <IAutoCompleteResultModel>(result.Predictions.Select(p =>
                                                                                                              new AutoCompleteResultModel
                {
                    PrimaryText   = p.StructuredFormatting?.MainText,
                    SecondaryText = p.StructuredFormatting?.SecondaryText,
                    PlaceId       = p.PlaceId,
                    Icon          = "marker.png"
                }));

                return(addresses);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            return(null);
        }