Google Place自动完成

阿约德·凯德(Ayodele Kayode)

我正在尝试添加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数据库,如果该代码正确,我就不会这样做,因为我尚未测试过

奇拉格·纳哈尔(Chirag Nahar)

我有同样的问题。确保您启用了适用于Android的Google Places API,而不仅仅是启用了开发者控制台中的Places API “ Android的Places API”将不会显示在API和Auth / API下,因为它尚未流行。您将必须使用API​​搜索框进行搜索。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何实现Google商家编程自动完成

Google Places机场自动完成

Google Place自动完成功能会限制国家/地区搜索结果吗?

Google自动完成语言

Google Place API自动完成搜索,半径作为严格过滤条件

如何在Android Google Place的自动完成活动中更改占位符文本?

Google Place Autcomplete地址API强制HTML自动完成=关

结合使用经纬度的Google Place自动完成网络服务

Google Place API:如何自动完成API以进行自定义搜索?

Google地图使用角度材料自动完成

QtQuick文本搜索使用Google自动完成自动完成

如何将Google Place自动完成api结果限制为仅纽约?

如何在MapKit JS中创建类似于Google的Place Autocomplete的自动完成查找

Coffeescript遍历Google Place自动完成功能

Google GeoCode自动完成限制状态

Google Place by classname自动完成功能不起作用

将Google Maps Place Form集成到自动完成地址表单javascript中

实施Google Place自动完成

放置Google Api-自动完成

Google Maps自动完成完整地址

Google Place自动完成功能会影响输入中的按键按下行为

Google Place Api用于获取地点的自动完成建议

使用Google Place自动完成功能的ngMap的离子模态不会选择预测

Google地方信息自动完成“ place_changed”事件不起作用

AngularJS-Google Place自动完成API密钥

Django的。Google Place自动填写地址表格

Google Maps API - 自动完成英国县

对 AJAX 内容运行 Google 自动完成

从 Google Places api 自动完成获取时区