java - getPlaceById() fails to return data on Android google places API / resultCallback not getting called -


i cannot retrieve place details using google places api on android. i'm calling getplacybyid() specific place_id.

inside android activity setup googleapiclient , call connect(). apiclient connects successfully.

then testing purposes call getplacebyid() using hardcoded place_id , resultcallback. however, resultcallback never gets called.

the hardcoded place_id tested through javascript (using javascript google maps api) , returns valid data. java code below fails return data.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.some_activity_layout);     butterknife.inject(this);     if (getactionbar() != null) {         getactionbar().setdisplayhomeasupenabled(true);     }      if (mgoogleapiclient == null) {         rebuildgoogleapiclient();     }     .....     code_for_activity_init     ..... }  protected synchronized void rebuildgoogleapiclient() {     // when build googleapiclient specify connected , connection failed     // callbacks should returned, google apis our app uses , oauth 2.0     // scopes our app requests.     mgoogleapiclient = new googleapiclient.builder(this)             //.enableautomanage(this, 0 /* clientid */, this)             .addconnectioncallbacks(this)             .addapi(places.geo_data_api)             .build(); }  @override protected void onstart() {     super.onstart();     mgoogleapiclient.connect(); }  @override protected void onstop() {     super.onstop();     mgoogleapiclient.disconnect(); }   @override public void onconnected(bundle bundle) {     // connected api client. pass adapter enable api access.     //addressesadapter.setgoogleapiclient(mgoogleapiclient);     log.i("place api conn", "googleapiclient connected.");  }  @override public void onconnectionsuspended(int i) {     // connection api client has been suspended. disable api access in client.     //madapter.setgoogleapiclient(null);     log.e("place api conn", "googleapiclient connection suspended."); }  @onlongclick(r.id.one_more_request) public boolean getdataagain(){     log.d("place", "getplace id");     pendingresult<placebuffer> placeresult = places.geodataapi             .getplacebyid(mgoogleapiclient, "chijiv6mkke9orqrcpq3kax513m");     placeresult.setresultcallback(mupdateplacedetailscallback);     return true; }  private resultcallback<placebuffer> mupdateplacedetailscallback         = new resultcallback<placebuffer>() {     @override     public void onresult(placebuffer places) {         if (!places.getstatus().issuccess()) {             // request did not complete             log.e("place", "place query did not complete. error: " + places.getstatus().tostring());              return;         }         // place object buffer.         final place place = places.get(0);          // format details of place display , show in textview.         //mplacedetailstext.                 toast.maketext(myactivity.this,/*settext(*/                         formatplacedetails(getresources(), place.getname(),                 place.getid(), place.getaddress(), place.getphonenumber(),                 place.getwebsiteuri()), toast.length_long).show();          log.i("place", "place details received: " + place.getname());     } }; 

this question similar google places api resultcallback not firing have checked androidmanifest includes the required permission

<uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> 

ultimately getplacebyid() called every time user selects item autocomplete address field.

***** update ******* solution found. missing 2 things. first, copy-paste maps.v2.api_key time geo.api_key (and make sure delete maps.v2.api_key, because cannot specified twice)

android:name="com.google.android.maps.v2.api_key" android:value="whatevergooglemapsapikeyyouhave"

<meta-data         android:name="com.google.android.geo.api_key"         android:value="whatevergooglemapsapikeyyouhave"/> 

and secondly had enable google places api android

update sdk 21

if have both meta-data's included following error:

 caused by: java.lang.runtimeexception: api key can specified once. 

instead indlude geo api key:

<meta-data         android:name="com.google.android.geo.api_key"         android:value="whatevergooglemapsapikeyyouhave"/> 

and not maps 1


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -