Hi, The permissions and the settings are correct. I think it crashes if it isn't.
I changed my function a bit such that the update request has a minimum delay of 10 seconds and 10 meters. But I still get no updates. I can get the last known location from the location manager so I figured that works. Just the LocationListener's methods never gets called somehow... On Sep 7, 10:44 am, The Bear <bernard.mcca...@googlemail.com> wrote: > Make sure you add the line > <permission android:name="android.permission.ACCESS_FINE_LOCATION"></ > uses-permission> > to your AndroidManifest.xml file and you have enabled GPS satellites > on your handset (won't work otherwise). > > Then try this: > > public class GPSTest extends Activity { > private TextView text; > private LocationManager manager; > private LocationListener listener; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > text = (TextView)findViewById(R.id.Text); > > manager = (LocationManager) getSystemService > (Context.LOCATION_SERVICE); > Location myLocation = manager.getLastKnownLocation("gps"); > > text.setText(("Lat: " + myLocation.getLatitude() > + "\nLLong: " + myLocation.getLongitude())); > > listener = new MyLocationListener(); > manager.requestLocationUpdates("gps" ,10000L, 10.0f, > listener); > } > > private class MyLocationListener implements LocationListener{ > > public void onLocationChanged(Location location) { > // TODO Auto-generated method stub > if (location != null){ > text.setText(("Lat: " + location.getLatitude() > + "\nLLong: " + location.getLongitude())); > } > } > > public void onProviderDisabled(String provider) { > // TODO Auto-generated method stub > } > > public void onProviderEnabled(String provider) { > // TODO Auto-generated method stub > } > > public void onStatusChanged(String provider, int status, > Bundle extras) { > // TODO Auto-generated method stub > } > } > > } > > On Sep 4, 8:49 am, Xster <x...@xiao-yu.com> wrote: > > > > > Hi, > > > I'm trying to start a GPS program and I'm just trying out the first > > step to display coordinates as they change. > > > I followedhttp://www.devx.com/wireless/Article/39239andused the > > LocationManager and LocationListener classes. > > > Code: > > public class GPSTest extends Activity { > > /** Called when the activity is first created. */ > > > private TextView text; > > private LocationManager manager; > > private LocationListener listener; > > > @Override > > public void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > setContentView(R.layout.main); > > > text = (TextView) findViewById(R.id.Text); > > > manager = (LocationManager) getSystemService > > (Context.LOCATION_SERVICE); > > listener = new MyLocationListener(); > > manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, > > 0, 0, listener); > > } > > > private class MyLocationListener implements LocationListener{ > > > public void onLocationChanged(Location location) { > > // TODO Auto-generated method stub > > if (location != null){ > > text.setText(text.getText() + "\n" + > > location.getLatitude() + ", " > > + location.getLongitude() + " - " + location.getAccuracy()); > > } > > } > > > public void onProviderDisabled(String provider) { > > // TODO Auto-generated method stub > > > } > > > public void onProviderEnabled(String provider) { > > // TODO Auto-generated method stub > > > } > > > public void onStatusChanged(String provider, int status, > > Bundle > > extras) { > > // TODO Auto-generated method stub > > > } > > > } > > > } > > > However, once I run the code on the phone, the GPS icon is seen > > flashing but nothing happens. The method onLocationChanged is never > > reached (according to breakpoints). What am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---