I am implementing Google Places Autocomplete in my Xamarin Android project. (This is not a Xamarin Forms Project). When I search first time, the autocomplete works properly but consequent searches do not work properly.
Even if the autocomplete works, if I select an item, it will not call OnActivityResult
function and get back the above screen again.
Even these posts did not solve my problem
- Google Places Autocomplete Can't load search results
- Android onActivityResult not called / triggered
I have not set a billing account but I dont think that is the problem because it works sometimes. How can I solve this issue?
(Please note this is not a duplicate question since I could not find any questions like this)
This is the code I am using to open Google Places Autocomplete view
private void BtnLocationOnClick(object sender, EventArgs e)
{
List<Place.Field> fields = new List<Place.Field>();
fields.Add(Place.Field.Id);
fields.Add(Place.Field.Name);
fields.Add(Place.Field.LatLng);
fields.Add(Place.Field.Address);
Intent intent = new Autocomplete.IntentBuilder(AutocompleteActivityMode.Overlay, fields)
.SetCountry("US")
.Build(this);
StartActivityForResult(intent, 1);
}
Once the item is selected OnActivityResult
function need to be called
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == 1)
{
if (resultCode == Android.App.Result.Ok)
{
Place place = Autocomplete.GetPlaceFromIntent(data);
txtLocation.Text = place.Name;
googleMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(place.LatLng, 15));
}
}
}