Download presentation
Presentation is loading. Please wait.
Published byChester Ramsey Modified over 9 years ago
1
Android Accessing GPS Ken Nguyen Clayton State University 2012
2
Settings/ Manifest Add uses permission to allow access to device component and services Emulator: mock location data by Window Show View Other Android Emulator Control – In Emulator Control panel enter the GPS coordinates under Location Controls and press Send Ex: (both satellite and cell towels) –
3
Creating a Location Aware Activity public class MainActivityGPS extends Activity implements LocationListener{ private LocationManager mgr; private TextView output; private String best; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_activity_gps); mgr = (LocationManager) getSystemService(LOCATION_SERVICE); output = (TextView) findViewById(R.id.output); log("Location providers:"); dumpProviders(); //helper method to display the data
4
The following methods must be implemented for LocationListener Criteria c = new Criteria(); best = mgr.getBestProvider(c, true); //helper method to display the data log("\nBest provider is:" + best); log("\nLocation (starting with last known):"); if(best != null){ Location loc = mgr.getLastKnownLocation(best); log(loc.toString()); }
5
private void dumpProviders() { List providers = mgr.getAllProviders(); for(int i = 0 ; i < providers.size(); i++){ log(providers.get(i).toString()); } private void log(String string) { output.append(string); } //required public void onLocationChanged(Location location) { log("\n" + location.toString()); } //required public void onStatusChanged(String provider, int status, Bundle extras) { log("\n" + lprovider.toString()); }
6
Suggested apps Build an app to log the GPS coordinates of the device The app must have – Start/stop/pause – Export / email coordinates – Map coordinates – Clear/reset
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.