迁移新的Place SDK客户端后,将LatLng参数设置为null

问题描述 投票:1回答:1

最近我在我的应用程序中迁移了新的SDK客户端,但是将latLng参数设置为null,使用以下依赖项

'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 {addr ess = 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},likelihoodLikelihood {place = Place {address = null,attributions = null,id = null,latLng = null,name = Shan ti 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 = nu ll,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 = n ull,types = null,userRatingsTotal = null,viewport = null

无法弄清楚为什么除了名字之外,每件东西都会变为空

android google-maps google-places-api google-places
1个回答
0
投票

最后我得到了答案实际上我错过了传递所需的参数,在创建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);
© www.soinside.com 2019 - 2024. All rights reserved.