【问题标题】:Place AutoComplete Prediction放置自动完成预测
【发布时间】:2020-08-04 08:52:55
【问题描述】:

我没有得到任何回应。我错过了什么? 谁能给我一个想法。有错误。

        IPlacesClient placesClient = PlacesApi.CreateClient(CrossCurrentActivity.Current.Activity);
        PlacesApi.Initialize(CrossCurrentActivity.Current.Activity, "********API KEY***************");  
        var token = AutocompleteSessionToken.NewInstance();
        var request = FindAutocompletePredictionsRequest.InvokeBuilder()
            .SetSessionToken(token)
            .SetTypeFilter(TypeFilter.Establishment)
            .SetCountry("US")
            .SetQuery("Ind")
            .Build();
        Task<FindAutocompletePredictionsResponse> task = placesClient.FindAutocompletePredictions(request);

【问题讨论】:

  • 添加 Google 自动完成功能后,您需要自己的有效 Google API 和通过 Google Developers Console 设置项目。我没有看到您的 API 密钥在哪里,您可以通过 Google 搜索获得很多信息。
  • API 密钥已添加。我已经编辑了我的查询。在谷歌

标签: xamarin.android autocomplete google-places-api google-places googleplacesautocomplete


【解决方案1】:

可以参考https://github.com/xamarin/XamarinComponents/blob/master/Android/GooglePlaces/samples/PlacesSample/MainActivity.cs

你的方法是对的。 您必须为您的任务添加一个操作。

task.AddOnSuccessListener(CrossCurrentActivity.Current.Activity, this);
task.AddOnFailureListener(CrossCurrentActivity.Current.Activity, this);

然后,为每个动作添加代码

public void OnSuccess(Java.Lang.Object result)
{
  //Do something
}
public void OnFailure(Java.Lang.Exception e)
{
  //Failed
}

记得实现 IOnSuccessListener、IOnFailureListener 和 IOnCompleteListener

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-26
    相关资源
    最近更新 更多