Reputation: 732
I added to my android application 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.
I searched the reason (and a solution) on stackoverflow. I found some posts saying to put the API key that we can found on the google developer console inside:
<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.
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.
Upvotes: 1
Views: 1002
Reputation: 11
I think you haven't enabled "Google Places API for Android" in your API console, Enable it. I have faced same problem once. I solved using the above solution.
Upvotes: 1