gpt4 book ai didi

android - Google 地方信息自动完成

转载 作者:行者123 更新时间:2023-11-29 18:45:12 25 4
gpt4 key购买 nike

我正在尝试添加 google place 自动完成功能,它工作得很好,但每次我点击它来搜索我的位置时,我的键盘都会显示,然后立即消失

代码xml

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true" />

</RelativeLayout>
</android.support.v7.widget.CardView>

java代码

PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
location = place.getName().toString();

FirebaseUser current_user = FirebaseAuth.getInstance().getCurrentUser();
String user_id = current_user.getUid();
mDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(user_id);

HashMap<String, String> userMap = new HashMap<>();
userMap.put("User location", location);


mDatabase.setValue(userMap).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {

if(task.isSuccessful()){

Intent addlocation = new Intent(selectlocation.this, home.class);
addlocation.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(addlocation);
finish();


}

}
});
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
}
});

而且我还没有测试过,但是如果正确使用它,请帮助我检查 java 代码。我正在尝试将用户位置发送到我的 firbase 数据库,我不知道该代码是否正确,因为我还没有测试过它

最佳答案

我遇到了同样的问题。确保在 Developer Console 中启用适用于 Android 的 Google Places API 而不仅仅是 Places API . “Places API for Android”不会出现在 APIs & Auth/APIs 下,因为它还不是一个流行的 API(目前)。您必须使用 API 搜索框进行搜索。

关于android - Google 地方信息自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52154839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com