google maps - Unable to get current location problems (android, permission) -


i've dev first application , make simple map activity, latitude , longitude 0. (when start activity cursor should set in device location). set permission in manifest , google-services.json file, still have error:

e/gmpm: googleservice failed initialize, status: 10, missing expected resource: 'r.string.google_app_id' initializing google services. possible causes missing google-services.json or com.google.gms.google-services gradle plugin.

i think why cant correct longitude , latitude.

activity code:

public class ********activity extends fragmentactivity implements onmapreadycallback,googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener {  private googlemap mmap; double latitude, longitude; googleapiclient mgoogleapiclient; location mlastlocation;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_locate_match);      buildgoogleapiclient();      if (mgoogleapiclient != null) {         mgoogleapiclient.connect();     } else         toast.maketext(this, "not connected...", toast.length_short).show();      // obtain supportmapfragment , notified when map ready used.     supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager()             .findfragmentbyid(r.id.map);     mapfragment.getmapasync(this); }  protected void onstart() {     mgoogleapiclient.connect();     super.onstart(); }  protected void onstop() {     mgoogleapiclient.disconnect();     super.onstop(); }   public void onconnectionfailed(connectionresult arg0) {     toast.maketext(this, "failed connect...", toast.length_short).show();  }   public void onconnectionsuspended(int arg0) {     toast.maketext(this, "connection suspended...", toast.length_short).show();  }   public void onconnected(bundle arg0) {     mlastlocation = locationservices.fusedlocationapi.getlastlocation(mgoogleapiclient);      if (activitycompat.checkselfpermission(this, manifest.permission.access_fine_location) != packagemanager.permission_granted){         // todo: consider calling         //    activitycompat#requestpermissions         // here request missing permissions, , overriding         //   public void onrequestpermissionsresult(int requestcode, string[] permissions,         //                                          int[] grantresults)         // handle case user grants permission. see documentation         // activitycompat#requestpermissions more details.         log.i("permission","problems");         return;     }      if (mlastlocation != null) {         latitude = mlastlocation.getlatitude();         longitude = mlastlocation.getlongitude();         log.i("latitude",""+latitude);         log.i("longitude",""+longitude);     }  }   protected synchronized void buildgoogleapiclient() {     mgoogleapiclient = new googleapiclient.builder(this)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this)             .addapi(locationservices.api)             .build(); }   /**  * manipulates map once available.  * callback triggered when map ready used.  * can add markers or lines, add listeners or move camera. in case,  * add marker near sydney, australia.  * if google play services not installed on device, user prompted install  * inside supportmapfragment. method triggered once user has  * installed google play services , returned app.  */ @override public void onmapready(googlemap googlemap) {     mmap = googlemap;      latlng pos = new latlng(latitude,longitude);     mmap.addmarker(new markeroptions().position(pos).title("user marker"));     mmap.movecamera(cameraupdatefactory.newlatlng(pos)); } } 

manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.marcocreation.******">  <!-- auto-complete email text field in login form user's emails --> <uses-permission android:name="android.permission.get_accounts" /> <uses-permission android:name="android.permission.read_profile" /> <uses-permission android:name="android.permission.read_contacts" /> <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_fine_location" />   <!--      access_coarse/fine_location permissions not required use      google maps android api v2, must specify either coarse or fine      location permissions 'mylocation' functionality.  --> <application     android:allowbackup="true"     android:icon="@mipmap/soccer"     android:label="@string/app_name"     android:launchmode="singletop"     android:supportsrtl="true"     android:theme="@style/apptheme">     <meta-data         android:name="com.facebook.sdk.applicationid"         android:value="@string/facebook_app_id" />     <meta-data         android:name="com.google.android.geo.api_key"         android:value="@string/google_maps_key" />     <meta-data android:name="com.google.android.gms.version"         android:value="@integer/google_play_services_version" />     <activity         android:name="com.facebook.facebookactivity"         android:configchanges="keyboard|keyboardhidden|screenlayout|screensize|orientation"         android:label="@string/app_name"         android:theme="@android:style/theme.translucent.notitlebar" />     <activity         android:name=".mainactivity"         android:theme="@style/apptheme">         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     <activity         android:name=".loginactivity"         android:label="@string/title_activity_login"         android:parentactivityname=".mainactivity">         <meta-data             android:name="android.support.parent_activity"             android:value="com.marcocreation.******.mainactivity" />     </activity>     <activity         android:name=".homeuseractivity"         android:label="@string/title_activity_home_user"         android:theme="@style/apptheme" />     <activity         android:name=".registeractivity"         android:label="@string/title_activity_register"         android:parentactivityname=".mainactivity"         android:theme="@style/apptheme">         <meta-data             android:name="android.support.parent_activity"             android:value="com.marcocreation.*******.mainactivity" />     </activity>     <activity         android:name=".profileactivity"         android:label="@string/title_activity_profile"         android:theme="@style/apptheme" />     <activity         android:name=".profileactivity2"         android:label="@string/title_activity_profile2"         android:theme="@style/apptheme" />     <!--          api key google maps-based apis defined string resource.          (see file "res/values/google_maps_api.xml").          note api key linked encryption key used sign apk.          need different api key each encryption key, including release key used          sign apk publishing.          can define keys debug , release targets in src/debug/ , src/release/.      -->       <activity         android:name=".locatematchactivity"         android:label="@string/title_activity_locate_match">         <meta-data             android:name="android.support.parent_activity"             android:value="com.marcocreation.********.profileactivity2" />     </activity> </application>  </manifest> 

gradle:

dependencies {     compile filetree(dir: 'libs', include: ['*.jar'])     testcompile 'junit:junit:4.12'      compile 'com.android.support:appcompat-v7:23.4.0'     compile 'com.android.support:design:23.4.0'     compile 'com.facebook.android:facebook-android-sdk:4.+'     compile 'com.google.android.gms:play-services:8.4.0' } 

reading log, saw "permission:problems" app seems not has right permission.

you need place configuration file (google-services.json) generated developer.google.com, mentioned in 2nd step of official docs here

please take @ post: googleservice failed initialize

it you


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -