-1

我想在我的 android 应用程序中使用谷歌地图地点选择器,但地点选择器已被弃用,并且不包含在新的地点 SDK 中。请告诉我如何在我的 android 应用中实现最新的 SDK

        new LatLng(47.64299816, -122.14351988));
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
builder.setLatLngBounds(latLngBounds);

try {
    startActivityForResult(builder.build(this), PLACE_PICKER_REQ_CODE);
} catch (Exception e) {
    Log.e(TAG, e.getStackTrace().toString());
}
4

1 回答 1

1

这是替代方案。

实施 'com.google.android.gms:play-services-places:16.1.0'

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

     Places.initialize(getApplicationContext(), getString(R.string.google_maps_key));

    PlacesClient placesClient = Places.createClient(this);

    mAutocompleteSupportFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.placeAutocompletefragment); // Fragment is declared in layout file 

    mAutocompleteSupportFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME, Place.Field.LAT_LNG));

    mAutocompleteSupportFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(@NonNull Place place) {

            Log.d("PlaceAddress", "onPlaceSelected: " + place.getLatLng());

            LatLng queriedLocation = place.getLatLng();
            Log.v("Latitude is", "" + queriedLocation.latitude);
            Log.v("Longitude is", "" + queriedLocation.longitude);

            mLat = queriedLocation.latitude;
            mLng = queriedLocation.longitude;


        }

        @Override
        public void onError(@NonNull Status status) {

        }
    });

在这里,您将获得所选地点的纬度。

于 2019-09-19T16:54:01.257 回答