我正在集成地点选择器,但我已经启用了地点 api,但它会立即打开和关闭。
我创建了 api 密钥并将其放在清单文件中仍然无法正常工作。在我的 logcat 中它给了我错误
2019-03-08 10:31:41.640 2837-2358/? E/Places:您的应用似乎没有启用 Places API for Android。有关更多详细信息,请参阅https://developers.google.com/places/android/signup。2019-03-08 10:31:41.651 4713-4713/? E/Places:Place Picker 由于 PLACES_API_ACCESS_NOT_CONFIGURED 2019-03-08 10:31:41.775 2837-2358/而关闭 E/Places:您的应用似乎没有启用 Places API for Android。有关更多详细信息,请参阅https://developers.google.com/places/android/signup。2019-03-08 10:31:41.776 2837-2358/? E/AsyncOperation: serviceID=65, operation=SearchPlaces OperationException[Status{statusCode=PLACES_API_ACCESS_NOT_CONFIGURED, resolution=null}]
这是我的代码
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="key" />
@SuppressLint("MissingPermission")
private void showPlacePicker() {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
startActivityForResult(builder.build(NewOrderActivity.this), PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(data, NewOrderActivity.this);
edt_pickup_address.setText(place.getAddress());
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> listAddresses = geocoder.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
if (null != listAddresses && listAddresses.size() > 0) {
/* post_area = listAddresses.get(0).getSubLocality();
post_city = listAddresses.get(0).getSubAdminArea();
post_state = listAddresses.get(0).getAdminArea();*/
}
} catch (IOException e) {
e.printStackTrace();
}
String place_phone_number = "" + place.getPhoneNumber();
if (!TextUtils.isEmpty(place_phone_number)) {
String[] phone_number = place_phone_number.split(" ");
String s = "";
for (int i = 0; i < phone_number.length; i++) {
if (i != 0) {
s = s + phone_number[i];
}
}
// et_contact_no_add_company.setText(s);
} else {
// et_contact_no_add_company.setText("");
}
if (place.getWebsiteUri() != null) {
// et_website_add_company.setText("" + place.getWebsiteUri());
} else {
// et_website_add_company.setText("");
}
}
}
}