简体   繁体   English

适用于 Android 的 Google Place API:无法使用地点选择器的选择器选择地点

[英]Google Place API for Android: can't select place with the picker of Place Picker

I added to my android application Place Picker.我添加到我的 android 应用程序 Place Picker。 When you know the address of the place you want to pick and fill the research bar, it works.当您知道要选择并填写研究栏的地点的地址时,它就起作用了。 But I want that the user has the possibility to choose the place of his choice in using the red picker and this part doesn't work.但是我希望用户可以在使用红色选择器时选择他选择的位置,这部分不起作用。

When you pick a place with the red picker and click "Select this location" like here .当你选择一个地方用红色选择器,然后单击“选择这个位置”喜欢这里

We can't select the place.我们无法选择地点。 The "Select" button is greyed out. “选择”按钮呈灰色。 Like you can observe here .就像你可以在这里观察。

Of course I have enabled the Google Place Android API and Google Maps Android API on the Google Developer Console.当然,我已经在 Google Developer Console 上启用了 Google Place Android API 和 Google Maps Android API。

I searched the reason (and a solution) on stackoverflow.我在 stackoverflow 上搜索了原因(和解决方案)。 I found some posts saying to put the API key that we can found on the google developer console inside:我发现一些帖子说要把我们可以在谷歌开发者控制台上找到的 API 密钥放在里面:

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

I did it but no positive result.我做到了,但没有积极的结果。

Then I tried to do again the implementation of Place Picker from scratch, without success.然后我尝试从头开始再次执行Place Picker,但没有成功。

This is the code where I use Place Picker:这是我使用地方选择器的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_location);
    Button chooseLocationButton = (Button) findViewById(R.id.choose_location);
    PlacePicker.IntentBuilder intentBuilder = new PlacePicker.IntentBuilder();
    try {
        final Intent intent = intentBuilder.build(this);
        chooseLocationButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(intent, REQUEST_PLACE_PICKER);
            }
        });

    } catch (GooglePlayServicesRepairableException e) {
        e.printStackTrace();
        // TODO handle exception!
    } catch (GooglePlayServicesNotAvailableException e) {
        e.printStackTrace();
        // TODO handle exception!
    }


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_PLACE_PICKER) {
        if (resultCode == RESULT_OK) {
            Place place = PlacePicker.getPlace(data, this);
            String toast = String.format("Place: %s", place.getName());
            longitude = place.getLatLng().longitude;
            latitude = place.getLatLng().latitude;
            Toast.makeText(this, toast, Toast.LENGTH_LONG).show();
        }
    }
}

I don't find anymore solution to try on the internet.我找不到更多的解决方案来尝试在互联网上。 It's why I write this question.这就是我写这个问题的原因。 Does anybody have any idea why this doesn't work?有谁知道为什么这不起作用?

Thank you.谢谢你。

I think you haven't enabled "Google Places API for Android" in your API console, Enable it.我认为您尚未在 API 控制台中启用“Google Places API for Android”,请启用它。 I have faced same problem once.我曾经遇到过同样的问题。 I solved using the above solution.我使用上述解决方案解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM