Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* V0.01
- * 4/10/11 - 2010
- * Just network data location
- *
- */
- package com.saltapps.satmap;
- import android.app.Activity;
- import android.location.Criteria;
- import android.location.LocationListener;
- import android.location.LocationManager;
- import android.os.Bundle;
- import android.widget.TextView;
- import android.widget.Toast;
- public class Location extends Activity implements LocationListener { // implement LocationListener, for getting network location data
- LocationManager locationManager;
- TextView tvLat, tvLongi; // textviews for location
- String towers; // used with location manager, to get location from service provider masts
- float lat, longi; // values for Location (longi, since long is Java keyword)
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.location); // lays the activity out according to the main.xml file in the res/layout folder
- locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // get location manager
- tvLat = (TextView) findViewById(R.id.tvLat); // for displaying latitude and longitude values
- tvLongi = (TextView) findViewById(R.id.tvLongi);
- Criteria crit = new Criteria();
- towers = locationManager.getBestProvider(crit, false); // gets best data according to criteria. Our criteria is default, so we should get best data
- android.location.Location location = locationManager.getLastKnownLocation(towers); // gets last known location using network data from masts
- if (location != null) { // checks that location information is present
- lat = (float) (location.getLatitude()); // gets latidude
- longi = (float) (location.getLongitude()); // gets longitude
- tvLat.setText("Latitude: " + lat); // displays latitude
- tvLongi.setText("Longitude: " + longi); // displays longitude
- } else {
- Toast.makeText(this, "Couldn't get provider", Toast.LENGTH_SHORT).show(); // displays briefly
- } // if/else
- } // onCreate
- @Override
- public void onResume() { // actions to carry out upon returning to this activity
- super.onResume(); //
- } // onResume
- @Override
- public void onPause() { // actions to carry out when activity isn't in focus
- super.onPause();
- } // onPause
- public void onLocationChanged(Location location) { // Ignore (for now)
- // TODO Auto-generated method stub
- } // onLocationChanged
- public void onProviderDisabled(String provider) { // Ignore (for now)
- Toast.makeText(this, "Couldn't get provider", Toast.LENGTH_SHORT).show();
- } // onProviderDisabled
- public void onProviderEnabled(String provider) { // Ignore (for now)
- // TODO Auto-generated method stub
- } // onProviderEnabled
- public void onStatusChanged(String provider, int status, Bundle extras) { // Ignore (for now)
- // TODO Auto-generated method stub
- } // onStatusChanged
- public void onLocationChanged(android.location.Location arg0) {
- // TODO Auto-generated method stub
- } // onLocationChanged
- } // class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement