我使用下面给出的代码(取自here)来获取给定PlaceDetails
的{{1}},但Google Places API会不断返回以下状态。
状态:
placeId
Status{statusCode=unknown status code: 9000, resolution=null}
已建立联系。 Google Developer Console还会显示已收到2个请求,并且已报告2个错误。
我使用此link为指定位置获得了GoogleApiClient
。
代码:
placeId
相关的清单项目:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient
.Builder(this)
.addApi(Places.GEO_DATA_API)
.addApi(Places.PLACE_DETECTION_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
public void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
// TODO Auto-generated method stub
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS)
{
Log.e("HELLOPPPPPPPPP", "GOOOOOGLE API Connected: df ");
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeID)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
Log.e("HELLOPPPPPPPPP",
"onResult is invoked at least: status = " + places.getStatus()
+ ", count = " + places.getCount());
if (places.getStatus().isSuccess()) {
final Place myPlace = places.get(0);
Log.e("HELLOPPPPPPPPP", "Place f ound: " + myPlace.getName());
}
places.release();
}
});
}
else
{
Log.e("HELLOPPPPPPPPP", "NOTTTTTTTTT GOOOOOGLE API Connected: df ");
}
}
Google Developer Console设置:
我已经启用了适用于Android的Google Places API&#39;和Google地图定位API&#39;在控制台设置上。我正在为我的应用程序使用Android Key。
答案 0 :(得分:0)
这是我用来查询地方详细信息的方法。 Alias是一个具有Google地方ID
的自定义模型void queryPlaceDetails(final Alias alias) {
showProgressDialog("Getting place details");
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi.getPlaceById(googleApiClient, alias.getPlaceId());
placeResult.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(PlaceBuffer places) {
hideProgressDialog();
..do stuff here with results
}
});
}
仔细检查您的密钥哈希值是否正确