【发布时间】:2015-07-06 23:42:39
【问题描述】:
我使用下面给定的代码(取自here)来获取给定placeId 的PlaceDetails,但Google Places API 不断返回以下状态。
状态:
Status{statusCode=unknown status code: 9000, resolution=null}
GoogleApiClient 已连接。 Google Developer Console 还显示,例如收到了 2 个请求,并报告了 2 个错误。
我使用此link 获得了给定位置的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 ");
}
}
相关清单项:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="<MyKey>" />
</application>
Google 开发者控制台设置:
我在控制台设置中启用了“Android 版 Google Places API”和“Google Maps Geolocation API”。我正在为我的应用程序使用 Android Key。
【问题讨论】:
-
你能解释一下你到底想要什么吗?
标签: android google-places-api google-geocoding-api