我正在尝试通过Google实现Place Picker
API。但是每次我开始活动时,活动都会立即关闭。
用于实现位置选择器的代码:
int PLACE_PICKER_REQUEST = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pop_up_2);
btn3 = (Button) findViewById(R.id.button2);
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
Context context = getApplicationContext();
try {
startActivityForResult(builder.build(context), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, this);
String toastMsg = String.format("Place: %s", place.getName());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
}
}
API密钥已在清单文件中声明:
<manifest>
<application
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_place_api" />
</application>
</manifest>
Logcat错误:
BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/placesandroid/v1/search?key=AIzaSyCHWpRWCGo_YUKwzHn4Qv6yP5q9E5TNRJA
2019-04-28 07:49:21.729 2875-5225/? E/Places: Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
即使在我的帐户上启用了Google地方信息,为什么也会出现此错误?
注意:我还设置了我的结算帐户。
答案 0 :(得分:0)
您的应用似乎未启用Android的Places API:请仔细检查
class(x)