I am trying to get a place by passing the place_id to the Places.GeoDataApi but it is not returning anything and I am sure that the place_id is correct.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Places.GEO_DATA_API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).build();
String placeId = "ChIJja4QaeH0GjkRKK5cBjTfKQo";
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(@NonNull PlaceBuffer places) {
if(places.getStatus().isSuccess() && places.getCount()>0){
final Place myPlace = places.get(0);
Log.i(String.valueOf(MainActivity.this),
"Place found: " + myPlace.getName() + "\n Address: " + myPlace.getAddress());
} else {
Log.i(String.valueOf(MainActivity.this),"Place not found!");
}
places.release();
}
});
}
Edit: Added manifest.xml file
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<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">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MY_API_KEY"/>
</application>