Tom*_*mCB 5 android google-maps-api-3 google-places-api google-places-autocomplete
我正在尝试实现Places API。我的代码如下所示:
val builder = PlacePicker.IntentBuilder()
startActivityForResult(builder.build(mActivity), PLACE_PICKER_REQUEST)
Run Code Online (Sandbox Code Playgroud)
我的地图凭据是正确的,但是这次通话我得到了
Places API for Android does not seem to be enabled for your app. See https://developers.google.com/places/android/signup for more details.
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试启用“ Android的Places API”时,出现此错误。
您没有足够的权限来查看此页面。
我尝试注销帐户,然后以隐身模式,Safari和Chrome重新登录。什么都没用,所以我联系了支持部门,支持非常快(谢谢大家!)
尝试启用Places for Android API时收到错误的原因是,该信息已被弃用。现在,启用Places API将涵盖android的Places功能。
我询问了实施情况,并得到了答复。
地点选择器也已弃用。您可以安装兼容性库以继续使用位置选择器,直到弃用期在7月29日结束为止。有关此内容的更多信息,请点击此处红色:https : //developers.google.com/places/android-sdk/client-migration#place_picker
我现在在网上找到的文档有些混乱,什么不推荐使用,什么不推荐?谁能为我指出这种功能的正确方向?
Nav*_*mar 15
Google Places SDK for Android is Deprecated, so we need to migrate for Places API. For implementing AutoComplete Place using new Places API.. please follow below steps.
First enable PlacesAPI in developer console, then install Client Library by updating in gradle.
(Note: You can only install either the client library or the compatibility library, NOT both)
implementation 'com.google.android.libraries.places:places:1.0.0'
Run Code Online (Sandbox Code Playgroud)
Now initialize below code inside Oncreate();
// Add an import statement for the client library.
import com.google.android.libraries.places.api.Places;
// Initialize Places.
Places.initialize(getApplicationContext(), "***YOUR API KEY***");
// Create a new Places client instance.
PlacesClient placesClient = Places.createClient(this);
Run Code Online (Sandbox Code Playgroud)
New PlacesAPI is initialised..
For AutoComplete places use below code (You can use AutoComplete Fragment also)
// Set the fields to specify which types of place data to return.
List<Place.Field> fields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Start the autocomplete intent.
Intent intent = new Autocomplete.IntentBuilder(
AutocompleteActivityMode.FULLSCREEN, fields)
.build(this);
startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Place place = Autocomplete.getPlaceFromIntent(data);
Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
} else if (resultCode == AutocompleteActivity.RESULT_ERROR) {
// TODO: Handle the error.
Status status = Autocomplete.getStatusFromIntent(data);
Log.i(TAG, status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
}
}
}
Run Code Online (Sandbox Code Playgroud)
REMOVE(if you added)
implementation 'com.google.android.gms:play-services-places:16.0.0'
Run Code Online (Sandbox Code Playgroud)
Required header files
import com.google.android.libraries.places.api.Places;
import com.google.android.libraries.places.api.model.Place;
import com.google.android.libraries.places.api.net.PlacesClient;
import com.google.android.libraries.places.widget.Autocomplete;
import com.google.android.libraries.places.widget.AutocompleteActivity;
import com.google.android.libraries.places.widget.model.AutocompleteActivityMode;
Run Code Online (Sandbox Code Playgroud)
Hope this will help..
| 归档时间: |
|
| 查看次数: |
8232 次 |
| 最近记录: |