Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 迁移new Place SDK客户端后获取LatLng参数null_Android_Google Maps_Google Places Api_Google Places - Fatal编程技术网

Android 迁移new Place SDK客户端后获取LatLng参数null

Android 迁移new Place SDK客户端后获取LatLng参数null,android,google-maps,google-places-api,google-places,Android,Google Maps,Google Places Api,Google Places,最近,我已经在我的应用程序中迁移了新的PlaceSDK客户端,但是使用以下依赖项获得了latLng参数null 'implementation 'com.google.android.libraries.places:places:1.0.0' 实现了以下代码 List<Place.Field> placeFields = Arrays.asList(Place.Field.NAME); FindCurrentPlaceRequest request = F

最近,我已经在我的应用程序中迁移了新的PlaceSDK客户端,但是使用以下依赖项获得了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());
                }
            });
List placeFields=Arrays.asList(Place.Field.NAME);
FindCurrentPlaceRequest=FindCurrentPlaceRequest.builder(placeFields.build();
//调用findCurrentPlace并处理响应(首先检查用户是否已授予权限)。
placesClient.findCurrentPlace(请求).addOnSuccessListener((响应)->{
FindCurrentPlaceResponse mFindCurrentPlaceResponse=响应;
Log.i(“MainActivity”,mFindCurrentPlaceResponse.toString());
sourceTxt.setText(response.getplacelikelikelihoods().get(0.getPlace().getAddress());
RIDE_REQUEST.put(“s_地址”,response.getPlaceLikeLikeLihoods().get(0.getPlace().getAddress());
RIDE_REQUEST.put(“s_纬度”,response.getPlaceLikeLikeLihoods().get(0.getPlace().getLatlings()!=null?response.getPlaceLikeLikeLihoods().get(0.getPlace().getLatlings().latitude:0.0);
RIDE_REQUEST.put(“s_经度”,response.GetPlaceLikeLikeLihoods().get(0.getPlace().getLatLng()!=null?response.GetPlaceLikeLikeLihoods().get(0.GetPlaceLikeLikeLikeLihoods().getLatLng()经度:0.0);
})).addOnFailureListener((异常)->{
if(ApiException的异常实例){
ApiException=(ApiException)异常;
Log.e(“MainActivity”,“未找到位置:”+apiException.getStatusCode());
}
});
得到以下回应

FindCurrentPlaceResponse{PlaceLikeLikeLihoods=[PlaceLikeLike{place=place{address=null,Attributes=null,id=null,latLng=null,name=Shri Vallabh Galaxy,openingHours=null,phoneNumber=null,PhotoMetadata=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},likelization=0.157329110992432},placelikelization{place=place{address=null,attributes=null,id=null,latLng=null,name=Simran Manor,openingHours=null,phoneNumber=null,photommetadata=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},likelization=0.12205597015381},placelikelization{place=place{address=null,attributes=null,id=null,latLng=null,name=Adinath Heights,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},likelization=0.12109905291992},placelikelization{placelikelization=place{address=null,attributes=null,id=null,latLng=null,name=Shanti Heights公寓,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},libility=0.1030252025203471},placelibility{placelibility=place{address=null,attributes=null,id=null,latLng=null,name=Vrind residentity,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},似然度=0.09741650581359863},place似然度{place似然度{place{address=null,Attributes=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},似然性=0.06733533382415771},place似然性{place似然性{place=place=place=place{address=null,Attributes=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},似然性=0.05104345798492432},place似然性{place似然性{place=place=place}{address=null,Attributes=null,id=null,latLng=null,name=Navin Pri Matric Anusuchit Jati Kanya Chatrawas,openingHours=null,phoneNumber=null,Photometadata=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},似然性=0.0458361721038184},place似然性{地点{{address=null,Attributes=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},似然性=0.02887811899185181},place似然性{place似然性{place=place=place}{address=null,attributes=null,id=null,latLng=null,name=Shiv Temple,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},似然度=0.0205793617248535},place似然度{place{address=null,attributes=null,id=null,latLng=null,name=NRB Indore,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null,websiteUri=null},似然度=0.01465254068374663},place似然度{place=place{address=null,Attributes=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},似然性=0.013667398969117737},place似然性{place似然性{place=place=place{address=null,attributes=null,id=null,latLng=null,name=RBD Block C,openingHours=null,phoneNumber=null,photometadas=null,plusCode=null,priceLevel=null,rating=null,types=null,userRatingsTotal=null,viewport=null


无法理解为什么除了名称之外所有的东西都是空的

最后我得到了答案,实际上我没有传递所需的参数, 创建placeFields对象时,我只是一个pas
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);