title: Get GPS Location in a Broadcast Receiver/or Service to Broadcast Receiver data transfer
body: <p>I am new to android.<br>
  I want to get GPS  Location  in a broadcast receiver but it shows an error.</p>
  
  <p>My code is :</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      LocationManager locManager = (LocationManager) 
              getSystemService(Context.LOCATION_SERVICE);
      // errors in getSystemService method
      LocationListener locListener = new MyLocationListener();
      locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
              locListener);
      Location loc = locManager
              .getLastKnownLocation(LocationManager.GPS_PROVIDER);
      Log.d(" **location**", " location" + loc.getLatitude());
  }
  </code></pre>
  
  <p>Questions :</p>
  
  <ol>
  <li>Is it possible to get GPS Location data in Broadcast receiver? </li>
  <li>Another alternative way I tried so far was to use a service which is invoked by the Broadcast receiver. The service can get GPS data, but how can I get it in the Broadcast receiver?</li>
  </ol>