迁移新的 Place SDK 客户端后获取 LatLng 参数 null

Getting LatLng parameter null after Migrating the new Place SDK Client

最近我在我的应用程序中迁移了新的 place SDK 客户端,但得到 latLng 参数为空,使用以下依赖项

'implementation 'com.google.android.libraries.places:places:1.0.0'

实现了以下代码

List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME);
            FindCurrentPlaceRequest request = FindCurrentPlaceRequest.builder(placeFields).build();
            // Call findCurrentPlace and handle the response (first check that the user has granted permission).
            placesClient.findCurrentPlace(request).addOnSuccessListener(((response) -> {
                FindCurrentPlaceResponse mFindCurrentPlaceResponse = response;
                Log.i("MainActivity", mFindCurrentPlaceResponse.toString());
                sourceTxt.setText(response.getPlaceLikelihoods().get(0).getPlace().getAddress());
                RIDE_REQUEST.put("s_address", response.getPlaceLikelihoods().get(0).getPlace().getAddress());
                RIDE_REQUEST.put("s_latitude", response.getPlaceLikelihoods().get(0).getPlace().getLatLng() != null ? response.getPlaceLikelihoods().get(0).getPlace().getLatLng().latitude : 0.0);
                RIDE_REQUEST.put("s_longitude", response.getPlaceLikelihoods().get(0).getPlace().getLatLng() != null ? response.getPlaceLikelihoods().get(0).getPlace().getLatLng().longitude : 0.0);
            })).addOnFailureListener((exception) -> {
                if (exception instanceof ApiException) {
                    ApiException apiException = (ApiException) exception;
                    Log.e("MainActivity", "Place not found: " + apiException.getStatusCode());
                }
            });

得到以下响应

FindCurrentPlaceResponse{placeLikelihoods=[PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Shri Vallabh Galaxy, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.1573291110992432}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Simran Manor, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.1220559597015381}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Adinath Heights, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.1210990524291992}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Shanti Heights Apartment, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.1030252552032471}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Vrind Residency, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.09741650581359863}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Radha Rukmani Garden, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.06733533382415771}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Shanti Heights Block-B, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.05104345798492432}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Navin Pri Matric Anusuchit Jati Kanya Chatrawas, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.04583617210388184}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Shanti Heights, Block - D, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.02887811899185181}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Shiv Temple, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.02057793617248535}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=NRB Indore, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.01496525406837463}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=Swapnil Palace, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null, websiteUri=null}, likelihood=0.01366739869117737}, PlaceLikelihood{place=Place{address=null, attributions=null, id=null, latLng=null, name=RBD Block C, openingHours=null, phoneNumber=null, photoMetadatas=null, plusCode=null, priceLevel=null, rating=null, types=null, userRatingsTotal=null, viewport=null

无法弄清楚为什么除了名称之外的所有内容都为空

最后我得到了答案实际上我缺少传递所需的参数, 在创建 placeFields 对象时,我只传递了 Place.Field.Name

List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME);

但是为了让事情正常进行,我需要将所有必需的参数传递给我,我需要从这样的响应中获得这些参数

List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.LAT_LNG,Place.Field.ADDRESS);