【问题标题】:PlaceAutoCompleteTextView in map在地图中放置 AutoCompleteTextView
【发布时间】:2019-11-11 14:34:43
【问题描述】:

我一直在尝试在我的 2 AutoCompleteTextView 中添加位置预测列表,我也在我的项目中实现了它,但现在我的 DashboardActivity 在设置适配器时出错。设置适配器时错误转换错误的类型

activity_dashboard.xml

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <fragment
                android:id="@+id/map"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:name="com.google.android.gms.maps.SupportMapFragment" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:src="@drawable/map_marker"
                />
            <RelativeLayout
                android:id="@+id/pickupRL"
                android:layout_width="match_parent"
                android:layout_alignParentTop="true"
                android:layout_height="50dp"
                android:layout_marginTop="5pt"
                android:layout_marginLeft="10pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                android:background="@drawable/white_border" >

                <ImageView
                    android:id="@+id/pickupIV"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_marginRight="3pt"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5pt"
                    android:src="@drawable/ic_search"
                    app:tint="@color/colorPrimaryDark"/>

                <AutoCompleteTextView
                    android:id="@+id/pickupATV"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toRightOf="@+id/pickupIV"
                    android:layout_centerVertical="true"
                    android:textSize="15sp"
                    android:textColor="@color/colorBlack"
                    android:background="@null"
                    android:hint="Search location"
                    android:singleLine="true"
                    android:imeOptions="actionSearch"/>

            </RelativeLayout>

            <RelativeLayout
                android:id="@+id/dropoffRL"
                android:layout_marginTop="5pt"
                android:layout_below="@id/pickupRL"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:layout_marginLeft="10pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                android:background="@drawable/white_border" >

                <ImageView
                    android:id="@+id/dropoffIV"
                    android:layout_width="15dp"
                    android:layout_height="15dp"
                    android:layout_marginRight="3pt"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="5pt"
                    android:src="@drawable/ic_search"
                    app:tint="@color/colorPrimaryDark"/>

                <AutoCompleteTextView
                    android:id="@+id/dropoffATV"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_toRightOf="@+id/dropoffIV"
                    android:layout_centerVertical="true"
                    android:textSize="15sp"
                    android:textColor="@color/colorBlack"
                    android:background="@null"
                    android:hint="Search location"
                    android:singleLine="true"
                    android:imeOptions="actionSearch"/>

            </RelativeLayout>

            <Button
                android:id="@+id/btnconfirm"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="30dp"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:padding="20dp"
                android:text="Comfirm" />

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/currentLocationFAB"
                android:backgroundTint="@color/colorWhite"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@id/btnconfirm"
                android:layout_alignParentRight="true"
                android:layout_marginBottom="5pt"
                android:layout_marginRight="10pt"
                android:elevation="4pt"
                app:fabSize="mini"
                app:borderWidth="0dp"
                app:elevation="4pt"
                app:backgroundTint="@color/colorWhite"
                android:src="@drawable/ic_current_location"
                android:tint="@color/colorPrimaryDark"/>

        </RelativeLayout>

DashboardActivity.java

public class DashboardActivity extends AppCompatActivity implements OnMapReadyCallback, View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {

    private Activity activity;
    private GoogleMap mMap;
    private static final String Tag = "MAP_ACTIVITY";
    private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
    private static final String COURSE_LOCATION = Manifest.permission.ACCESS_COARSE_LOCATION;
    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
    private static final float DEFAULT_ZOOM = 15f;
    private static final LatLngBounds LAT_LNG_BOUNDS = new LatLngBounds(
            new LatLng(-40, -168), new LatLng(71, 136));

    private Boolean mLocationPermissionsGranted = false;
    private FusedLocationProviderClient mFusedLocationProviderClient;
    private final ThreadLocal<PlaceAutocompleteAdapter> mplaceAutoCompeleteAdapter = new ThreadLocal<>();

    private GoogleApiClient mGoogleApiClient;
    private PlaceInfo mPlace;

    private AutoCompleteTextView pickupATV, dropoffATV;
    private Button btnconfirm;
    private FloatingActionButton currentLocationFAB;
    private Toolbar toolbar;
    private MenuItem previousItem;
    private UtilityModel utilityModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);

        bindControls();
        bindListeners();
        getLocationPermission();
        setMap();
    }

    private void getLocationPermission() {
        String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.ACCESS_COARSE_LOCATION};

        if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
                    COURSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                mLocationPermissionsGranted = true;
                setMap();
            } else {
                ActivityCompat.requestPermissions(this,
                        permissions,
                        LOCATION_PERMISSION_REQUEST_CODE);
            }
        } else {
            ActivityCompat.requestPermissions(this,
                    permissions,
                    LOCATION_PERMISSION_REQUEST_CODE);
        }
    }

    private void bindControls() {
        activity = DashboardActivity.this;
        utilityModel = new UtilityModel(activity);
        toolbar = findViewById(R.id.toolbar);

        btnconfirm = findViewById(R.id.btnconfirm);
        pickupATV = findViewById(R.id.pickupATV);
        dropoffATV = findViewById(R.id.dropoffATV);
        currentLocationFAB = findViewById(R.id.currentLocationFAB);
    }


    private void bindListeners() {
        btnconfirm.setOnClickListener(this);

        mGoogleApiClient = new GoogleApiClient
                .Builder(this)
                .addApi(com.google.android.gms.location.places.Places.GEO_DATA_API)
                .addApi(Places.PLACE_DETECTION_API)
                .enableAutoManage(this, this)
                .build();

        mplaceAutoCompeleteAdapter.set(new PlaceAutocompleteAdapter(activity, mGoogleApiClient, LAT_LNG_BOUNDS, null));
        pickupATV.setOnItemClickListener(mAutocompleteClickListener);
        pickupATV.setAdapter(mplaceAutoCompeleteAdapter); // This adapter is causing the trouble
        pickupATV.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || keyEvent.getAction() == KeyEvent.ACTION_DOWN
                        || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER) {

                    //execute our method for searching
                    geoLocate(pickupATV);
                }

                return false;
            }
        });

        dropoffATV.setOnItemClickListener(mAutocompleteClickListener);
        mplaceAutoCompeleteAdapter.set(new PlaceAutocompleteAdapter(activity, mGoogleApiClient, LAT_LNG_BOUNDS, null));
        dropoffATV.setAdapter(mplaceAutoCompeleteAdapter); // This adapter is causing the trouble
        dropoffATV.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH
                        || actionId == EditorInfo.IME_ACTION_DONE
                        || keyEvent.getAction() == KeyEvent.ACTION_DOWN
                        || keyEvent.getAction() == KeyEvent.KEYCODE_ENTER) {

                    //execute our method for searching
                    geoLocate(dropoffATV);
                }

                return false;
            }
        });

        currentLocationFAB.setOnClickListener(this);
        utilityModel.hideSoftKeyboard();
    }

    private AdapterView.OnItemClickListener mAutocompleteClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            utilityModel.hideSoftKeyboard();

            final AutocompletePrediction item = mplaceAutoCompeleteAdapter.get().getItem(i);
            final String placeId = item.getPlaceId();

            PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
                    .getPlaceById(mGoogleApiClient, placeId);
            placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
        }
    };

    private ResultCallback<PlaceBuffer> mUpdatePlaceDetailsCallback = new ResultCallback<PlaceBuffer>() {
        @SuppressLint("RestrictedApi")
        @Override
        public void onResult(@NonNull PlaceBuffer places) {
            if(!places.getStatus().isSuccess()){
                Log.d(Tag, "onResult: Place query did not complete successfully: " + places.getStatus().toString());
                places.release();
                return;
            }
            final Place place = places.get(0);

            try{
                mPlace = new PlaceInfo();
                mPlace.setName(place.getName().toString());
                Log.d(Tag, "onResult: name: " + place.getName());
                mPlace.setAddress(place.getAddress().toString());
                Log.d(Tag, "onResult: address: " + place.getAddress());
                mPlace.setAttributions(place.getAttributions().toString());
//                Log.d(TAG, "onResult: attributions: " + place.getAttributions());
                mPlace.setId(place.getId());
                Log.d(Tag, "onResult: id:" + place.getId());
                mPlace.setLatlng(place.getLatLng());
                Log.d(Tag, "onResult: latlng: " + place.getLatLng());
                mPlace.setRating(place.getRating());
                Log.d(Tag, "onResult: rating: " + place.getRating());
                mPlace.setPhoneNumber(place.getPhoneNumber().toString());
                Log.d(Tag, "onResult: ic_phone number: " + place.getPhoneNumber());
                mPlace.setWebsiteUri(place.getWebsiteUri());
                Log.d(Tag, "onResult: website uri: " + place.getWebsiteUri());
                Log.d(Tag, "onResult: place: " + mPlace.toString());
            }catch (NullPointerException e){
                Log.e(Tag, "onResult: NullPointerException: " + e.getMessage() );
            }
            setMarkerAndMoveCamera(new LatLng(place.getViewport().getCenter().latitude,
                    place.getViewport().getCenter().longitude), mPlace);
            currentLocationFAB.setVisibility(View.VISIBLE);

            places.release();
        }
    };

    private void geoLocate(AutoCompleteTextView view) {
        String searchString = view.getText().toString().trim();

        Geocoder geocoder = new Geocoder(activity);
        List<Address> list = new ArrayList<>();
        try {
            list = geocoder.getFromLocationName(searchString, 1);
        } catch (IOException e) {
            Log.e(Tag, "geoLocate: IOException: " + e.getMessage());
        }

        if (list.size() > 0) {
            Address address = list.get(0);

            setMarkerAndMoveCamera(new LatLng(address.getLatitude(), address.getLongitude()), null);
        }
    }

    private void setMap() {
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;
        if (mLocationPermissionsGranted) {
            getCurrentLocation();
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
                    != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
                    Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                return;
            }
            mMap.setMyLocationEnabled(true);
            mMap.getUiSettings().setMyLocationButtonEnabled(false);

            mMap.setOnCameraMoveListener(new GoogleMap.OnCameraMoveListener() {
                @SuppressLint("RestrictedApi")
                @Override
                public void onCameraMove() {
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });

            mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
                @Override
                public void onMarkerDragStart(Marker marker) {

                }

                @Override
                public void onMarkerDrag(Marker marker) {

                }

                @SuppressLint("RestrictedApi")
                @Override
                public void onMarkerDragEnd(Marker marker) {
                    setMarkerAndMoveCamera(marker.getPosition(), null);
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });

            mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
                @SuppressLint("RestrictedApi")
                @Override
                public void onMapClick(LatLng latLng) {
                    setMarkerAndMoveCamera(latLng, null);
                    currentLocationFAB.setVisibility(View.VISIBLE);
                }
            });
        }
    }

    private void getCurrentLocation() {
        mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
        try {
            if (mLocationPermissionsGranted) {
                final Task location = mFusedLocationProviderClient.getLastLocation();
                location.addOnCompleteListener(new OnCompleteListener() {
                    @Override
                    public void onComplete(@NonNull Task task) {
                        if (task.isSuccessful()) {
                            Log.d(Tag, "onComplete: found location!");
                            Location currentLocation = (Location) task.getResult();
                            setMarkerAndMoveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),null);
                        } else {
                            Log.d(Tag, "onFailed: current location is null");
                            Toast.makeText(activity, "unable to get current location", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        } catch (SecurityException e) {
            Log.e(Tag, "getCurrentLocation: SecurityException: " + e.getMessage());
        }
    }

    private void setMarkerAndMoveCamera(LatLng latLng, PlaceInfo placeInfo){
        mMap.clear();
        mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, DEFAULT_ZOOM));
    }


    @SuppressLint("RestrictedApi")
    @Override
    public void onClick(View v) {
        if (v == btnconfirm) {
//            LatLng currentMarkerLocation = mMap.getCameraPosition().target;
        }  else if (v == currentLocationFAB) {
            currentLocationFAB.setVisibility(View.INVISIBLE);
            getCurrentLocation();
        }
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    }
}

PlaceInfo.java

public class PlaceInfo {
    private String name;
    private String address;
    private String phoneNumber;
    private String id;
    private Uri websiteUri;
    private LatLng latlng;
    private float rating;
    private String attributions;

    public PlaceInfo(String name, String address, String phoneNumber, String id, Uri websiteUri,
                     LatLng latlng, float rating, String attributions) {
        this.name = name;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.id = id;
        this.websiteUri = websiteUri;
        this.latlng = latlng;
        this.rating = rating;
        this.attributions = attributions;
}

    public PlaceInfo() {

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }
    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Uri getWebsiteUri() {
        return websiteUri;
    }

    public void setWebsiteUri(Uri websiteUri) {
        this.websiteUri = websiteUri;
    }

    public LatLng getLatlng() {
        return latlng;
    }
    public void setLatlng(LatLng latlng) {
        this.latlng = latlng;
    }

    public float getRating() {
        return rating;
    }

    public void setRating(float rating) {
        this.rating = rating;
    }

    public String getAttributions() {
        return attributions;
    }

    public void setAttributions(String attributions) {
        this.attributions = attributions;
    }

    @Override
    public String toString() {
        return "PlaceInfo{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", phoneNumber='" + phoneNumber + '\'' +
                ", id='" + id + '\'' +
                ", websiteUri=" + websiteUri +
                ", latlng=" + latlng +
                ", rating=" + rating +
                ", attributions='" + attributions + '\'' +
                '}';
    }
}

PlaceAutocompleteAdapter.java

public class PlaceAutocompleteAdapter
    extends ArrayAdapter<AutocompletePrediction> implements Filterable {

private static final String TAG = "PlaceAutocompleteAd";
private static final CharacterStyle STYLE_BOLD = new StyleSpan(Typeface.BOLD);
private ArrayList<AutocompletePrediction> mResultList;
private GoogleApiClient mGoogleApiClient;
private LatLngBounds mBounds;
private AutocompleteFilter mPlaceFilter;
public PlaceAutocompleteAdapter(Context context, GoogleApiClient googleApiClient,
                                LatLngBounds bounds, AutocompleteFilter filter) {
    super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1);
    mGoogleApiClient = googleApiClient;
    mBounds = bounds;
    mPlaceFilter = filter;
}

public void setBounds(LatLngBounds bounds) {
    mBounds = bounds;
}

@Override
public int getCount() {
    return mResultList.size();
}

@Override
public AutocompletePrediction getItem(int position) {
    return mResultList.get(position);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = super.getView(position, convertView, parent);

    AutocompletePrediction item = getItem(position);

    TextView textView1 = row.findViewById(android.R.id.text1);
    TextView textView2 = row.findViewById(android.R.id.text2);
    textView1.setText(item.getPrimaryText(STYLE_BOLD));
    textView2.setText(item.getSecondaryText(STYLE_BOLD));

    return row;
}

@Override
public Filter getFilter() {
    return new Filter() {
        @Override
        protected FilterResults performFiltering(CharSequence constraint) {
            FilterResults results = new FilterResults();

            ArrayList<AutocompletePrediction> filterData = new ArrayList<>();

            if (constraint != null) {
                filterData = getAutocomplete(constraint);
            }

            results.values = filterData;
            if (filterData != null) {
                results.count = filterData.size();
            } else {
                results.count = 0;
            }

            return results;
        }

        @Override
        protected void publishResults(CharSequence constraint, FilterResults results) {

            if (results != null && results.count > 0) {
                mResultList = (ArrayList<AutocompletePrediction>) results.values;
                notifyDataSetChanged();
            } else {
                notifyDataSetInvalidated();
            }
        }

        @Override
        public CharSequence convertResultToString(Object resultValue) {
            if (resultValue instanceof AutocompletePrediction) {
                return ((AutocompletePrediction) resultValue).getFullText(null);
            } else {
                return super.convertResultToString(resultValue);
            }
        }
    };
}

private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
    if (mGoogleApiClient.isConnected()) {
        Log.i(TAG, "Starting autocomplete query for: " + constraint);

        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);

        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);

        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");

        return DataBufferUtils.freezeAndClose(autocompletePredictions);
    }
    Log.e(TAG, "Google API client is not connected for autocomplete query.");
    return null;
}

}

我的错误位于bindListenerbindListener 方法中的DashboardActivity.javapickupATV.setAdapterdropoffATV.setAdapter

构建错误

任务 :app:compileDebugJavaWithJavac 失败 /Users/muhammadyousuf/StudioProjects/homemoversfyp/app/src/main/java/com/example/daniyal/fyp_project/activities/DashboardActivity.java:162: 错误:类 AutoCompleteTextView 中的方法 setAdapter 不能 适用于给定类型; pickATV.setAdapter(mplaceAutoCompeleteAdapter); // 这个适配器导致了问题 ^ 必需:T 找到:ThreadLocal 原因:推断类型不 符合上限 推断:ThreadLocal 上限:ListAdapter,Filterable 其中 T 是类型变量: T 扩展 ListAdapter,Filterable 在方法 setAdapter(T) 中声明 /Users/muhammadyousuf/StudioProjects/homemoversfyp/app/src/main/java/com/example/daniyal/fyp_project/activities/DashboardActivity.java:181: 错误:类 AutoCompleteTextView 中的方法 setAdapter 不能 适用于给定类型; dropoffATV.setAdapter(mplaceAutoCompeleteAdapter); // 这个适配器导致了问题 ^ 必需:T 找到:ThreadLocal 原因:推断类型不 符合上限 推断:ThreadLocal 上限:ListAdapter,Filterable 其中 T 是类型变量: T 扩展 ListAdapter,Filterable 在方法 setAdapter(T) 中声明 注意:某些输入文件使用或覆盖了已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。笔记: /Users/muhammadyousuf/StudioProjects/homemoversfyp/app/src/main/java/com/example/daniyal/fyp_project/activities/DashboardActivity.java 使用未经检查或不安全的操作。注意:重新编译 -Xlint:详细信息未选中。 2 个错误

FAILURE:构建失败并出现异常。

出了什么问题:任务执行失败 ':app:compileDebugJavaWithJavac'。编译失败;看编译器 详细信息错误输出。

【问题讨论】:

    标签: android-studio


    【解决方案1】:

    我通过使用另一种方法自己解决了这个问题,该方法是developers.google.com 在文档中使用的新方法。我使用第一种方法添加为自动完成小部件。

    在我的活动的 onCreate 上,我初始化了 Places 实例。

    Places.initialize(getApplicationContext(), getResources().getString(R.string.google_maps_key));
    PlacesClient placesClient = Places.createClient(activity);
    

    在我的 onCreate 上,我再次初始化并声明了我的pickupFragment,并将它与一个监听器绑定。

    pickupFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.pickupFragment);
    pickupFragment.setCountry("PK");
    pickupFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.ADDRESS, Place.Field.LAT_LNG));
    pickupFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                // TODO: Get info about the selected place.
                Log.e(TAG, "Place: " + place.getName() + ", " + place.getId() + ", " + place.getLatLng());
            }
    
            @Override
            public void onError(Status status) {
                // TODO: Handle the error.
                Log.e(TAG, "An error occurred: " + status);
            }
        });
    

    并在我的 xml 中使用了这段代码

    <fragment
     android:id="@+id/pickupFragment"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />
    

    我为pickupFragment 和dropoffFragment 都这样做了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多