Reputation: 344
I've been stuck on this problem for quite some time and read all the earlier posts on stackOverflow, however none of them has solved my my problem. I've done everything mentioned however as soon as i launch the placePicker, it closes immediately.
The posts I've already been referred to are:
Here is the code for the PlacePicker:
public class Questions extends AppCompatActivity {
Spinner help;
String selectedHelp;
ImageView mapImage;
int PLACE_PICKER = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_questions);
mapImage = (ImageView)findViewById(R.id.map);
Picasso.get().load(R.drawable.map1).into(mapImage);
mapImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedHelp.equals("Travel")){
} else {
try {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
startActivityForResult(builder.build(Questions.this), PLACE_PICKER);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == PLACE_PICKER){
if (resultCode == RESULT_OK){
Place place = PlacePicker.getPlace(data, this);
String toast = String.format("Place: %s", place.getLatLng());
Toast.makeText(getApplicationContext(), toast, Toast.LENGTH_LONG).show();
Log.i("LatLang: ", toast);
}
}
}}
My manifest :-
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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/API_KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Questions">
</activity>
</application>
I've been stuck on this issue for a very long time. this is for my college project. I've also successfully created and restricted the key as shown on google developers website. Any help would be really appreciated.
Upvotes: 0
Views: 145
Reputation: 4027
Google Places SDK is Depricated, You need to migrate new API "PLACES API"
Please refer docs.. https://developers.google.com/places/android-sdk/client-migration#place_picker
Upvotes: 1