Reputation: 61
I am using Google Places autocomplete for my xamarin.android application. I am calling "GetAutocompletePredictions". On "OnComplete(Task task)" method i am getting task where i am getting "AutocompletePredictionBufferResponse" but now i am unable to get AutocompletePredictionBuffer from AutocompletePredictionBufferResponse.
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using Android.Gms.Maps;
using Android.Gms.Location.Places;
using Android.Gms.Maps.Model;
using Android.Gms.Tasks;
using Android.Content;
using Android.Util;
using Android.Views;
using Android.Gms.Common.Apis;
using Android.Support.V4.App;
using System.Collections.Generic;
using Java.Lang;
using System.Reflection;
namespace GooglePlacesAndroidNative
{
[Activity(Label = "GooglePlacesAndroidNative", MainLauncher =
true, Icon = "@mipmap/icon")]
public class MainActivity : Activity, IOnCompleteListener,
IOnSuccessListener
{
GeoDataClient getGeoDataClient;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
LatLngBounds bounds = new LatLngBounds(new
LatLng(38.46572222050097, -107.75668023304138), new
LatLng(39.913037779499035, -105.88929176695862));
getGeoDataClient =
PlacesClass.GetGeoDataClient(Android.App.Application.Context,
null);
Android.Gms.Tasks.Task result =
getGeoDataClient.GetAutocompletePredictions("pune", bounds,
null);
result.AddOnCompleteListener(this);
result.AddOnSuccessListener(this);
}
public void OnComplete(Task task)
{
AutocompletePredictionBufferResponse test = (AutocompletePredictionBufferResponse)task.Result;
}
public void OnSuccess(Object result)
{
AutocompletePredictionBufferResponse test = (AutocompletePredictionBufferResponse)result;
}
}
}
My question is "getGeoDataClient.GetAutocompletePredictions("pune", bounds, null)" function is returning Android.Gms.Tasks.Task which is "AutocompletePredictionBufferResponse". In Java android "AutocompletePredictionBufferResponse" class has a functions like "get(int)", "getCount()" but in xamarin.android same function doesn't have all these functions from which i can get Placess info. Instead "AutocompletePredictionBuffer" has all these functions in xamarin.android. Now my question is when i get api response in OnComplete(Task) i am getting "AutocompletePredictionBufferResponse", from this class object how can i get all the info about PLacess or atleast how can i get "AutocompletePredictionBuffer" object.
Upvotes: 0
Views: 454
Reputation: 74164
Xamarin has Extension-based helpers and thus you can use C# style async/await with those Android.Gms.Tasks.Tasks via GetAutocompletePredictionsAsync
var bufferResponse = await getGeoDataClient.GetAutocompletePredictionsAsync("pune", bounds, null);
Or using Xamarin's Android.Gms.Extensions:
var result = await TasksExtensions.AsAsync<AutocompletePredictionBufferResponse>(getGeoDataClient.GetAutocompletePredictions("pune", bounds, null));
Upvotes: 1