Get Coordinates from Network Sensor

After you’ve gotten the GPS sensor working, changing or adding a network sensor is very easy. Add the following declaration after the gpsListener declaration:

LocationListener networkListener;

Copy the code that begins with gpsListener = and ends just before the locationManager.requestLocationUpdates line, and paste it back into the method just before the locationManager.requestLocationUpdates line. You should now have two duplicate gpsListeners. Change all the gpsListener variables in the code you just pasted to networkListener and then add another requestUpdates message after the one that is used to request GPS updates.

locationManager.requestLocationUpdates(LocationManager. ...

Get Learning Mobile App Development: A Hands-on Guide to Building Apps with iOS and Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.