Konstantinos Nikoloutsos
Konstantinos Nikoloutsos

Reputation: 2180

Place picker (Google maps) closes immediately although I have followed the steps in documentation

I have followed their documentation step by step but it does not function

meta-data
    android:name="com.google.android.geo.API_KHTYEY"
    android:value="API_KEY_KEY_HERE"/>
button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                try {
                    startActivityForResult(builder.build(activity), PLACE_PICKER_REQUEST);
                } catch (GooglePlayServicesRepairableException e) {
                    e.printStackTrace();
                } catch (GooglePlayServicesNotAvailableException e) {
                    e.printStackTrace();
                }
            }
        });

Result: The place picker activity start but closes immediately. I tried to find the solution but everybody was talking about putting the api_key in the right place. This is definitely not my problem, so can anyone shed a light on this?

Upvotes: 2

Views: 450

Answers (2)

Pavithra.S
Pavithra.S

Reputation: 1

  button.setOnClickListener(new View.OnClickListener()

{
    @Override
    public void onClick (View v){
    openPlacePicker ();
}
});


private void openPlacePicker() {
    PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder ();
    try {
        startActivityForResult ( builder.build ( this ), PLACE_PICKER_REQUEST );

        //Enable Wifi
        wifiManager.setWifiEnabled ( true );


    } catch (GooglePlayServicesRepairableException e) {
        // Log.d("Exception",e.getMessage());

        e.printStackTrace ();
    } catch (GooglePlayServicesNotAvailableException e) {
        //Log.d("Exception",e.getMessage());

        e.printStackTrace ();
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult ( requestCode, resultCode, data );

    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case PLACE_PICKER_REQUEST:
                Place place = PlacePicker.getPlace ( MainActivity.this, data );

                double latitude = place.getLatLng ().latitude;
                double longitude = place.getLatLng ().longitude;
                CharSequence address = place.getAddress ();
                String PlaceLatLng = String.valueOf ( latitude ) + " , " + String.valueOf ( longitude );

                tv_MyLocation.setText ( PlaceLatLng );

        }
    }

Upvotes: 0

a4dev92
a4dev92

Reputation: 561

It looks that to use Place Picker through the deprecation period you need to have "Places SDK for Android" service enabled. Since 29.01.2019 google is no longer alowing users to enable that service so if you didn't enable that service before 29.01.2019 you can't use Place Picker. Right now you can only enable "Places API" which doesn't work with Place Picker (only Places SDK for Android does). I have the same problem, look here: Android Place Picker with API KEY created after January 29, 2019

Upvotes: 1

Related Questions