title: Android Best Location Listener Implementation
body: <p>I have been working on a Location-based app, and everything is ok except for the location implementation, which is the core point. </p>
  
  <p>I know location is very expensive, but I couldn't handle this by taking into account battery consumption. </p>
  
  <p>Here is my current algorithm:</p>
  
  <p>Step 1: Create an alarm manager with time interval of 1 minute.</p>
  
  <p>Step 2: When alarm is triggered, start the location listener </p>
  
  <pre><code>if(settings.getBoolean("use_gps", false))
          manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
      manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,listener);
      manager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0,listener);
  </code></pre>
  
  <p>Step 3: Wait a max of 15 seconds for a location</p>
  
  <p>Step 4: When a location is received, stop the location listener..</p>
  
  <p>One of the problems is due to this: at 0 seconds,with 0 meters location accuracy, CPU usage increases tremendously -- 45% CPU when alarm is triggered, with 0-15 seconds of alarm. </p>
  
  <p>But when I look at battery usage of my app, the battery usage increase, after 1-2 hours, does not match the expectation: battery usage is only ~ 4% - 5%.</p>
  
  <p>The second problem comes when the user wants to get their location by GPS.  Because getting a location by GPS takes so long, compared with getting location from the network provider, I couldn't get the location by GPS. </p>
  
  <p>I have implemented this algorithm after implementing a lot of different methods. </p>
  
  <p>I am looking for recommendation from someone who has successfully implemented periodic location retrieval via GPS with low CPU usage.</p>