google play services - LocationListener triggers before the interval set in location request using gms android -
i want trigger locationchanged method tracking real time location. use below code achieve this. question gave interval of 5 seconds location changed method triggers @ every 3 seconds. tried changing priority same. mistake have done understanding logic ? thank in advance guidance.
mgoogleapiclient = new googleapiclient.builder(getcontext()) .addapi(locationservices.api) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build(); locationrequest = new locationrequest() //tried high accuracy thinking might matter priority doesn't effect .setpriority(locationrequest.priority_balanced_power_accuracy) .setinterval(5 * 1000); method triggers location request.
private void requestlocation() { if (build.version.sdk_int >= 23) { if (getactivity().checkselfpermission(manifest.permission.access_coarse_location) == packagemanager.permission_granted && getactivity().checkselfpermission(manifest.permission.access_fine_location) == packagemanager.permission_granted) locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, locationlistener); else locationservices.fusedlocationapi.requestlocationupdates(mgoogleapiclient, locationrequest, locationlistener); log.d(tag, "requestlocation: "); } } locationlistener instance.
locationlistener locationlistener = new locationlistener() { @override public void onlocationchanged(location location) { //log shows triggering @ every 3 seconds. log.d(tag, "onlocationchanged: "); if (mgoogleapiclient.isconnected()) { longitude = location.getlongitude(); latitude = location.getlatitude(); } } };
priority_balanced_power_accuracy combined faster setfastestinterval(long) , slower setinterval(long) interval. u can use both or setfastestinterval(long) described in docs
Comments
Post a Comment