We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Autocomplete Google Places

Thread ID:

Created:

Updated:

Platform:

Replies:

146114 Jul 20,2019 03:54 PM UTC Aug 28,2019 09:54 AM UTC Xamarin.Forms 3
loading
Tags: SfAutoComplete
Aviad Katani
Asked On July 20, 2019 03:54 PM UTC

Hey there!

I'm trying to achieve a situation where I search for results only for a SPECIFIC COUNTRY.
I tried to accomplish that with requests and it DOES WORK, though lagging and buggy. I'm not using any MVVM pattern.
So, the current problems are:
1.  If I write the address too fast, it won't do anything and the list will stay empty
2. Result is not restricted to a specific country
3. Too slow - I think it's because there is no delay between requests

Code:
XAML:
            <autocomplete:SfAutoComplete
                x:Name="placesAutoComplete"
                Grid.Row="3"
                AutoCompleteMode="SuggestAppend"
                PropertyChanging="PlacesAutoComplete_OnPropertyChanging" />
C#:
        private void PlacesAutoComplete_OnPropertyChanging(object sender, PropertyChangingEventArgs e)
        {
            Device.BeginInvokeOnMainThread(async() =>
            {
                try
                {
                    placesAutoComplete.AutoCompleteSource =
                        (List<string>) await MapHandler.GetPlacesAutocompleteAsync((sender as SfAutoComplete)?.Text);
                }
                catch (Exception err)
                {
                    System.Diagnostics.Debug.WriteLine("Exception with autocomplete: " + err.Message + " stack :" + err.StackTrace);
                }
            });
        }

The call for API:
        public static async Task<IEnumerable<string>> GetPlacesAutocompleteAsync(string search)
        {
            var request = string.Format("https://maps.googleapis.com/maps/api/place/autocomplete/xml?input={0}&key={1}",
                search, "APIKEY");
            HttpClient client = new HttpClient();
            client.MaxResponseContentBufferSize = 256000;
            var xml = await client.GetStringAsync(request);
            var results = XDocument.Parse(xml).Element("AutocompletionResponse")?.Elements("prediction");

            var suggestions = new List<string>();
            if (results != null)
                foreach (var result in results)
                {
                    var suggestion = result.Element("description")?.Value;
                    suggestions.Add(suggestion);
                }

            return suggestions;
        }

How should I go with improving this code?

Thanks in advance! :)

Muneesh Kumar G [Syncfusion]
Replied On July 22, 2019 12:45 PM UTC

Hi Aviad, 
 
Greetings from Syncfusion.  
 
We have checked the provided code snippet and we would like to let you know that the PropertyChanged getting invoked every time and if we need to achieve the requirement please use the ValueChanged, SelectionChanged Event for the purpose required. 
 
 
Please check with the sample and let us know if you have any other requirement. 
 
Regards,
Muneesh Kumar G. 
 
 


Aviad Katani
Replied On August 27, 2019 10:48 AM UTC

Hi Aviad, 
 
Greetings from Syncfusion.  
 
We have checked the provided code snippet and we would like to let you know that the PropertyChanged getting invoked every time and if we need to achieve the requirement please use the ValueChanged, SelectionChanged Event for the purpose required. 
 
 
Please check with the sample and let us know if you have any other requirement. 
 
Regards,
Muneesh Kumar G. 
 
 


Thank you, it is working. Though app crashes sometimes when a long addrss is displayed:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.


Muneesh Kumar G [Syncfusion]
Replied On August 28, 2019 09:54 AM UTC

Hi Aviad, 
 
We have checked with the long address in SfAutoComplete control and unfortunately, we could not able to reproduce the same.  
 
And if the issue is still persisting, please mention the RestUrl and platform details and also if possible, please provide the issue reproducing sample which will be helpful for us to analyze the issue and provide an appropriate solution. 
 
Please let us know if you have any concern. 
  
Regards,   
Muneesh Kumar G   
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon