Note that there are some explanatory texts on larger screens.

plurals
  1. POset Timeout for GPS listening
    primarykey
    data
    text
    <p>I'm able to get location update from network provider but when it comes to gps it takes a lot of time for the data to be picked. I want to keep a particular time for which only the GPS listener will work and then move on to network provider after sometime. How to fix this issue ?</p> <p>This is my code..</p> <pre><code>public void gpslocation() { final LocationManager locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateLocationForGeo(location); //update(location); // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { System.out.println(provider+ "enabled provider"); } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub System.out.println(provider+ "disabled provider"); networklocation(); } }; String locationProvider = LocationManager.GPS_PROVIDER; locationManager.requestLocationUpdates(locationProvider, 10 * 1000, (float) 10.0,locationListener); } public void networklocation() { final LocationManager locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { updateLocationForGeo(location); //update(location); // Called when a new location is found by the network location provider. makeUseOfNewLocation(location); } private void makeUseOfNewLocation(Location location) { // TODO Auto-generated method stub } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { System.out.println(provider+ "enabled provider"); } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub System.out.println(provider+ "disabled provider"); isGpsProvidersDisabled=true; } }; String timeProvider = LocationManager.NETWORK_PROVIDER; locationManager.requestLocationUpdates(timeProvider, 1 * 1000, (float) 10.0, locationListener); } public void updateLocationForGeo(Location location){ System.out.println("location updated"); double dev_lat = location.getLatitude(); double dev_lang = location.getLongitude(); boolean out_of_range=false; for(int i=0; i&lt;arrayLength; i++){ double lattDiff = Math.toRadians(latarr[i]-dev_lat); double longDiff = Math.toRadians(lonarr[i]-dev_lang); double distance=(Math.sin(lattDiff/2)*Math.sin(lattDiff/2))+(Math.sin(longDiff/2)*Math.sin(longDiff/2)*Math.cos( Math.toRadians(latarr[i]))*Math.cos( Math.toRadians(dev_lat))); System.out.println(distance+" distance" ); double c= (2 * Math.atan2(Math.sqrt(distance), Math.sqrt(1-distance))); double radius=radarr[i]* 1.60934; double d = 6371 * c; if(d&gt;radius) { out_of_range=true; continue; } else{ System.out.println("enjoy"); out_of_range=false; break; } } </code></pre> <p>Any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload