android - 在 PlaceAutocomplete (Google Api) 中预填充地址

标签 android google-maps autocomplete google-api

我在我的 android 项目中实现了 PlaceAutocomplete 一切工作正常,但是根据它的工作,调用这个(PlaceAutocomplete) Activity 时显示为空

enter image description here

使用这段代码启动代码:

Intent intent =new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY).build(getActivity());
startActivityForResult(intent, 0);

但是根据我的项目要求,我需要在此处预填充之前选择的地址(例如,我第一次选择了任何地址并将该地址设置到任何文本字段中,现在用户想要编辑该地址但是如果用户单击在 TextView 上自动完成显示为空)。

我尝试了很多,但没有找到任何解决方案。
有什么办法可以在 android 中实现吗???

最佳答案

找到了。

我早就期待这个答案了。

There is method in PlaceAutocomplete.IntentBuilder class i.e. zzfd(@Nullable String var1).

它需要一个字符串值(如果你想预填充你的地址)。因此您可以在调用 startActivityForResult() 时使用它。

代码如下:

Intent intent =new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                                    .zzfd(your_text_View.getText().toString())
                                    .build(getActivity());
startActivityForResult(intent, 1);

如果您在开始时没有地址,您可以在 zzfd() 中传递 null。

You send address also on "initial_query" KEY, that will also work same.

例如:

Intent intent =new PlaceAutocomplete.IntentBuilder(PlaceAutocomplete.MODE_OVERLAY)
                                   .build(getActivity());
if (!TextUtils.isEmpty(your_text_View.getText().toString())) {
intent.putExtra("initial_query", (your_text_View.getText().toString());
} else {
   intent.removeExtra("initial_query");
}
startActivityForResult(intent, 1);

关于android - 在 PlaceAutocomplete (Google Api) 中预填充地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44589489/

相关文章:

Android getResources/getIdentifier 不返回 ID

php - JSON解析android中共享首选项期间出错

缺少 Android javax.annotation.processing 包。不能使用抽象处理器

ios - 谷歌自动完成教程 places api for swift

Xcode 9 自动完成无法 100% 工作 - 部分工作

android - 处理 recyclerview 适配器(Kotlin)中的按钮点击?

javascript - 为 Google map 方向服务循环多个起点

android - 限制用户可以在 Mapview 上访问的区域

javascript - jQuery 自动完成过滤器按首字母匹配

autocomplete - 自动完成时如何记录最后一个搜索请求?