Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid service to update users' location
    primarykey
    data
    text
    <p>I am trying to create a android service that will give updates on the users' location every 5 minutes. I am using the DDMS to send coordinates to the emulator which works fine. I need to convert these coordinates and get the location Eg: New York and using a Toast, print it on screen. I am not using any maps i am trying to use the Geocoder to convert the coordinates supplied by DDMS into the location. I don't get errors but it seems that the coordinates are not being converted to the location and nothing is displayed on screen. Please help have been struggling with this for a very long time. Here is my code. Thanks </p> <pre><code>public class GetLocationService extends Service { protected LocationManager locationManager; Button start; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } @Override public int onStartCommand(Intent intent, int flags, int startId){ LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); LocationListener ll = new MyLocListener(); Location location = new Location("abc"); ll.onLocationChanged(location ); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, ll); return START_STICKY; } private class MyLocListener implements LocationListener { public void onLocationChanged(Location location) { if (location != null) { Log.d("LOCATION CHANGED", location.getLatitude() + ""); Log.d("LOCATION CHANGED", location.getLongitude() + ""); } double latitude = location.getLatitude(); double longitude = location.getLongitude(); Toast.makeText(getApplicationContext(), location.getLatitude() + "" + location.getLongitude(), Toast.LENGTH_LONG).show(); try{ Geocoder geo = new Geocoder(GetLocationService.this.getApplicationContext(), Locale.getDefault()); List&lt;Address&gt; addresses = geo.getFromLocation(latitude, longitude, 1); if (addresses.size() &gt; 0) { Log.d("TAG",addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +"," + addresses.get(0).getAdminArea() + "," + addresses.get(0).getCountryName()); } Toast.makeText(getApplicationContext(), addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +"," + addresses.get(0).getAdminArea() + "," + addresses.get(0).getCountryName(), Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); } } } } </code></pre> <p>////Start Service////</p> <pre><code> public class MyService extends Activity { @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.service); startService(new Intent(getBaseContext(), GetLocationService.class)); } } </code></pre> <p><img src="https://i.stack.imgur.com/x0qc0.png" alt="enter image description here"></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.
 

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