问题描述
我已经创建了谷歌在开发者控制台的一个项目,想使用谷歌Places API的为Android。我启用了API,并融入了我的Android应用程序按照在谷歌开发者网站的指南()。该API是给这个错误,调试和搜索互联网的小时(或几天)后,我无法缩小问题。任何线索将pciated为什么这个错误就要到了AP $ P $。
错误:状态{状态code = NETWORK_ERROR,分辨率= NULL}
下面是谷歌的样品code其中地方自动完成被调用的功能。
私人的ArrayList< PlaceAutocomplete> getAutocomplete(CharSequence的约束){
如果(mGoogleApiClient!= NULL){
Log.i(TAG启动自动完成查询:+约束); //提交查询到自动完成API和检索PendingResult即会
//包含查询完成后的结果。
PendingResult<自动完成predictionBuffer>结果=
Places.GeoDataApi
.getAutocomplete predictions(mGoogleApiClient,constraint.toString()
mBounds,mPlaceFilter); //这个方法应该被取消主UI线程。阻塞等待最多60秒
//对于从API的结果。
自动完成predictionBuffer自动完成predictions =结果
.await(60 TimeUnit.SECONDS); //确认查询成功完成,否则返回null
最终状态状态=自动完成predictions.getStatus();
如果(!status.isSuccess()){
Toast.makeText(的getContext(),错误联系API:+ status.toString()
Toast.LENGTH_SHORT).show();
Log.e(TAG错误获取自动完成prediction API调用:+ status.toString());
自动完成predictions.release();
返回null;
} Log.i(TAG,查询完成。收到的+自动完成predictions.getCount()
+predictions。); //将结果复制到我们自己的数据结构,因为我们无法守住缓冲区。
//自动完成prediction对象封装API响应(地方ID和说明)。 迭代器<自动完成prediction>迭代器=自动完成predictions.iterator();
ArrayList的resultList =新的ArrayList<>(自动完成predictions.getCount());
而(iterator.hasNext()){
自动完成prediction prediction = iterator.next();
//获取这个prediction的细节,并将其复制到一个新的PlaceAutocomplete对象。
resultList.add(新PlaceAutocomplete(prediction.getPlaceId()
prediction.getDescription()));
} //现在所有数据已被复制释放缓冲器。
自动完成predictions.release(); 返回resultList;
}
Log.e(TAG,谷歌API客户端未连接的自动完成查询。);
返回null;
}
AndroidManifiest.xml权限
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.ACCESS_NETWORK_STATE/>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION/>
<使用许可权的android:NAME =com.google.android.providers.gsf.permission.READ_GSERVICES/>
<使用特征的android:glEsVersion =0x00020000机器人:所需=真/>
您可以把空
,而不是 getAutocomplete predictions AutocompleteFilter财产
方法,如果你想获得任何类型的predictions。
I have created a project under google developer console and wanted to use Google Places API for Android. I have enabled the API and integrated into my android application as per the guidelines on Google developer website (https://developers.google.com/places/android/start). The API is giving this error and after hours (and days) of debugging and searching the internet I couldn't narrow down the problem. Any leads would be appreciated about why this error is coming up.
Error: Status{statusCode=NETWORK_ERROR, resolution=null}
The following is the function from the google sample code where Places Auto Complete is invoked.
private ArrayList<PlaceAutocomplete> getAutocomplete(CharSequence constraint) {
if (mGoogleApiClient != null) {
Log.i(TAG, "Starting autocomplete query for: " + constraint);
// Submit the query to the autocomplete API and retrieve a PendingResult that will
// contain the results when the query completes.
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
// This method should have been called off the main UI thread. Block and wait for at most 60s
// for a result from the API.
AutocompletePredictionBuffer autocompletePredictions = results
.await(60, TimeUnit.SECONDS);
// Confirm that the query completed successfully, otherwise return null
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
Toast.LENGTH_SHORT).show();
Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString());
autocompletePredictions.release();
return null;
}
Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
+ " predictions.");
// Copy the results into our own data structure, because we can't hold onto the buffer.
// AutocompletePrediction objects encapsulate the API response (place ID and description).
Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
while (iterator.hasNext()) {
AutocompletePrediction prediction = iterator.next();
// Get the details of this prediction and copy it into a new PlaceAutocomplete object.
resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
prediction.getDescription()));
}
// Release the buffer now that all data has been copied.
autocompletePredictions.release();
return resultList;
}
Log.e(TAG, "Google API client is not connected for autocomplete query.");
return null;
}
AndroidManifiest.xml permissions
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
You can put null
instead of AutocompleteFilter property in getAutocompletePredictions
method if you want to get predictions of any types.
这篇关于Android版谷歌错误的地方API:{状态状态code = NETWORK_ERROR,分辨率= NULL}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!