android - Google Place Api gives Status{statusCode=ERROR, resolution=null} -
below code neaby places @ current location.the code works , not without changing anything. why happens . have checked api key valid , status code "error" says operation failed no more detailed information on https://developers.google.com/android/reference/com/google/android/gms/common/api/commonstatuscodes.html#constants thank below activity:
public class placesapiactivity extends appcompatactivity implements onconnectionfailedlistener, googleapiclient.connectioncallbacks { private static final string log_tag = "ppppppppppppppppp"; private static final int google_api_client_id =0; private googleapiclient mgoogleapiclient; private static final int permission_request_code = 100; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_places_api); log.d("resuktfvvvfdfd", "oncreate: "); buildgoogleapiclient();} private synchronized void buildgoogleapiclient() { button currentbutton = (button) findviewbyid(r.id.currentbutton); mgoogleapiclient = new googleapiclient.builder(placesapiactivity.this) .addapi(places.place_detection_api) .addapi(places.geo_data_api) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .enableautomanage(this, google_api_client_id, this) .build(); mgoogleapiclient.connect(); log.d("connected", string.valueof(mgoogleapiclient.isconnected())); currentbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (mgoogleapiclient.isconnected()) { log.d("connected1", string.valueof(mgoogleapiclient.isconnected())); if (contextcompat.checkselfpermission(placesapiactivity.this, manifest.permission.access_fine_location) != packagemanager.permission_granted) { activitycompat.requestpermissions(placesapiactivity.this, new string[]{manifest.permission.access_fine_location}, permission_request_code); } else { callplacedetectionapi(); } } } }); } @override public void onconnectionfailed(connectionresult connectionresult) { log.e(log_tag, "google places api connection failed error code: " + connectionresult.geterrorcode()); toast.maketext(this, "google places api connection failed error code:" + connectionresult.geterrorcode(), toast.length_long).show(); } @override public void onrequestpermissionsresult(int requestcode, string permissions[], int[] grantresults) { switch (requestcode) { case permission_request_code: if (grantresults.length > 0 && grantresults[0] == packagemanager.permission_granted) { callplacedetectionapi(); } break; } } private void callplacedetectionapi() throws securityexception { log.d("mvkvkmvkmvkm", "callplacedetectionapi: "); pendingresult<placelikelihoodbuffer> result = places.placedetectionapi .getcurrentplace(mgoogleapiclient, null); log.d("result", result.tostring()); result.setresultcallback(new resultcallback<placelikelihoodbuffer>() { @override public void onresult(placelikelihoodbuffer likelyplaces) { system.out.println("inside callback..."); status status = likelyplaces.getstatus(); system.out.println("status.tostring"+status.tostring()); system.out.println(status.issuccess()); system.out.println(status.getstatuscode()); system.out.println(status.getstatusmessage()); system.out.println(status.getstatus()); (placelikelihood placelikelihood : likelyplaces) { log.i(log_tag, string.format("place '%s' " + "likelihood: %g", placelikelihood.getplace().getname(), placelikelihood.getlikelihood())); } likelyplaces.release(); } }); } @override public void onstop() { super.onstop(); mgoogleapiclient.disconnect(); } @override public void onconnected(@nullable bundle bundle) { } @override public void onconnectionsuspended(int i) { } }
android manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.******"> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_fine_location"/> <uses-permission android:name="android.permission.access_coarse_location" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".placesapiactivity"> <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.gms.version" android:value="@integer/google_play_services_version"/> <meta-data android:name="com.google.android.geo.api_key" android:value="a***************************o"/> </application> </manifest>
log screen
07-06 15:56:32.499 10925-10925/com.example.utkarsh.nearby d/connected1: true 07-06 15:56:32.500 10925-10925/com.example.utkarsh.nearby d/mvkvkmvkmvkm: callplacedetectionapi: 07-06 15:56:32.554 10925-10925/com.example.utkarsh.nearby d/result: com.google.android.gms.location.places.internal.zzj$1@5dd8757 07-06 15:56:42.610 10925-10925/com.example.utkarsh.nearby i/system.out: inside callback... 07-06 15:56:42.610 10925-10925/com.example.utkarsh.nearby i/system.out: status.tostringstatus{statuscode=error, resolution=null} 07-06 15:56:42.610 10925-10925/com.example.utkarsh.nearby i/system.out: false 07-06 15:56:42.610 10925-10925/com.example.utkarsh.nearby i/system.out: 13 07-06 15:56:42.611 10925-10925/com.example.utkarsh.nearby i/system.out: error 07-06 15:56:42.611 10925-10925/com.example.utkarsh.nearby i/system.out: status{statuscode=error, resolution=null}
after having lot of error code solved sending gps location in emulator. in android studio avd - android emulator, program running, clicked in "more" > "location" > set latitude , longitude , clicked in "send". next request getcurrentlocation() executed. can send location emulator before executing app. work well.
Comments
Post a Comment