【问题标题】:autocomplete fragment is not working properly自动完成片段无法正常工作
【发布时间】:2018-06-12 05:48:09
【问题描述】:

我已使用以下代码在我的应用程序中搜索地点。

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

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


        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                mGoogleMap.clear();
                mGoogleMap.addMarker(new MarkerOptions().position(place.getLatLng()).title(String.valueOf(place.getName())));
                mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(place.getLatLng()));
                mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(place.getLatLng(), 12.0f));

            }

但是每当我点击搜索框时,它会出现一秒钟然后消失。

请澄清我的疑问。

【问题讨论】:

    标签: android google-maps google-places-api


    【解决方案1】:

    这是使用 Google Maps Platform 开发时的常见问题。

    请按以下步骤操作:

    1- 登录 Google Cloud Console。

    2- 使用 API KEY 选择或创建您的关联项目。

    3- 在控制台中启用 Places API

    获取 API 密钥检查 Setup API KEY

    【讨论】:

    • 大哥,places autocomplete fragment and place autocomplete activity我都用过,activity正常但不是fragment,出现又消失...
    • 是的,我错过了 启用 Places SDK for Android。谢谢你,扎伊德。
    • @yahme3 是自动完成搜索地点现在工作了吗?
    猜你喜欢
    • 2011-09-16
    • 2014-05-18
    • 2020-10-12
    • 2018-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 2018-03-01
    相关资源
    最近更新 更多