迁移新的Place SDK客户端后,获取LatLng参数为空

时间:2019-02-25 17:26:48

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

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

'实施'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,类型= null,userRatingsTotal = null,viewport = null,siteUri = null},可能性= 0.1573291110992432},PlaceLikelihood {place = Place {address = null,归因= null,id = null, latLng = null,name = Simran Manor,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,rating = null,类型= null,userRatingsTotal = null,viewport = null,siteUri = null},似然性= 0.1220559597015381},位置相似性{place = Place {address = null,归因= null,id = null,latLng = null,name = Adinath Heights,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,等级= null,类型= null,userRatingsTotal = null,viewport = null,websiteUri = null},可能性= 1.1210990524291992},PlaceLikelihood {place = Place {a ddress = null,attributions = null,id = null,latLng = null,name = Shanti Heights Apartment,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,评级= null,类型= null, userRatingsTotal = null,viewport = null,websiteUri = null},可能性= 0.1030252552032471},PlaceLikelihood {place = Place {address = null,归因= null,id = null,latLng = null,名称= Vrind Residency,openingHours = null,电话号码= null,photoMetadatas = null,plusCode = null,priceLevel = null,rating = null,类型= null,userRatingsTotal = null,viewport = null,siteUri = null},可能性= 0.09741650581359863,PlaceLikelihood {place = Place {address = null ,归因= null,id = null,latLng = null,name = Radha Rukmani Garden,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,rating = null,类型= null,userRatingsTotal = null ,viewport = null,websiteUri = null},似然性= 0.06733533382415771},PlaceLikelihood {place = Place {address = null,归因= null,id = null,latLng = null,name = S hanti Heights Block-B,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,rating = null,类型= null,userRatingsTotal = null,viewport = null,websiteUri = null},可能性= 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},可能性= 0.04583617210388184,PlaceLikelihood {place = Place {address = null,归因= 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,siteUri = null },似然性= 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,类型= null,userRatingsTotal = null,viewport = null,siteUri = null},可能性= 0.020577936172485485},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},似然性= 0.01496525406837463},PlaceLikelihood {place = Place {address = null,归因= null,id = null,latLng = null,名称= Swapnil Palace,openingHours = null,电话号码= null,photoMetadatas = null,plusCode = null,priceLevel = null,rating = null,类型= null,userRatingsTotal = null,viewport = null,websiteUri = null},可能性= 0.01366739869117737,PlaceLikelihood {place = Place {address = null ,归因= null,id = null,latLng = null,名称= RBD块C,openingHours = null,phoneNumber = null,photoMetadatas = null,plusCode = null,priceLevel = null,ratin g = null,类型= null,userRatingsTotal = null,viewport = null

无法弄清楚为什么除了名字之外,所有事物都为空

1 个答案:

答案 0 :(得分: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);