Google Places API Android resultCallback没有触发

我使用Google Places API for Android,我似乎无法得到PendingResultresultCallback。这里是我的代码(示例代码到https://github.com/googlesamples/android-play-places/tree/master/PlaceComplete基本相同,除了在对话框)Google Places API Android resultCallback没有触发

adapter = ((MainActivity) getActivity()).getAdapter(); 

googleApiClient = ((MainActivity) getActivity()).getGoogleApiClient();

final AutoCompleteTextView tvCity = new AutoCompleteTextView(getActivity());

tvCity.setAdapter(adapter);

tvCity.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

final PlacesAutoCompleteAdapter.PlaceAutocomplete item = adapter.getItem(position);

final String placeId = String.valueOf(item.placeId);

PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi

.getPlaceById(googleApiClient, placeId);

placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {

@Override

public void onResult(PlaceBuffer places) {

if (places.getStatus().isSuccess()) {

final Place place = places.get(0);

cityCoordinates = place.getLatLng();

} else {

dialog.dismiss();

Toast.makeText(getActivity(), "There was an error, please try again", Toast.LENGTH_SHORT).show();

return;

}

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);

places.release();

}

});

}

});

回答:

我有同样的问题,因为我错过了,它允许API访问谷歌的基于Web的服务的许可

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 

回答:

作为参考,对任何人谁访问了这个问题,你一定要做下面的所有3个步骤:

添加您的API密钥到您的应用清单

<application> 

...

<meta-data

android:name="com.google.android.geo.API_KEY"

android:value="YOUR_API_KEY"/>

</application>

然后包括在您的表现为@Alex贝克建议

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 

而且也使谷歌Places API的为Android。 Google Places API是一个不同的API,您的呼叫将失败,Places AutoComplete status 9001

以上是 Google Places API Android resultCallback没有触发 的全部内容, 来源链接: utcz.com/qa/266458.html

回到顶部