0

I want to show place picker that user can choose location. But place picker activity automatically closes after launch. I've check the API key multiple times also search this topic in stackoverflow but none of comment works for me. Here is my code. Please help

This is Magnifest file

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature android:name="android.hardware.wifi" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

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

        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

Build.gradle (app module)

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.4.0'
compile 'com.google.android.gms:play-services-maps:11.8.0'
compile 'com.google.android.gms:play-services-places:11.8.0'
compile 'com.google.android.gms:play-services-location:11.8.0'
testCompile 'junit:junit:4.12'}

apply plugin: 'com.google.gms.google-services'

This is an activity

int PLACE_PICKER_REQUEST = 1;
TextView tvPlace;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pick_map);

    tvPlace = (TextView) findViewById(R.id.tvPlace);

    Button btnLocate = (Button) findViewById(R.id.btnPickhome);
    btnLocate.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
            try {
                Intent intent = builder.build(PickMapActivity.this);
                startActivityForResult(intent, 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(this, data);
            tvPlace.setText(place.getAddress());
        }
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
nksbakery
  • 3
  • 2
  • Search for "Exception" in your log, i guess you must register your app in Google Services API website – K.Os Feb 11 '18 at 16:40
  • Yes, I already saw this link but I do everything follow this but not working on my phone. But I just try to run on another phone it's finally working now. Thank you for helping me. – nksbakery Feb 11 '18 at 16:57

1 Answers1

0

Try to deploy your app in real phone not emulator....post your log?Places API throwing an exception in logs