Chris Pollett >
Students > [Bio] |
Deliverable #1Description:
My progress:
Source code package net.learn2develop; import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; import android.widget.Toast; public class GPSMap extends MapActivity { private LocationManager lm; private LocationListener locationListener; private MapView mapView; private MapController mc; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Log.d("onCreate", "testing in onCreate"); super.onCreate(savedInstanceState); setContentView(R.layout.main); //---use the LocationManager class to obtain GPS locations--- lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); lm.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locationListener); mapView = (MapView) findViewById(R.id.mapview1); mc = mapView.getController(); boolean on = true; Log.d("onCreate","setSatllite mode on = "+on); } public void onPause(){ lm.removeUpdates(locationListener); Log.d("onPause", "testing in onPause"); super.onPause(); } @Override protected boolean isRouteDisplayed() { return false; } private class MyLocationListener implements LocationListener { @Override public void onLocationChanged(Location loc) { if (loc != null) { Toast.makeText(getBaseContext(), "Location changed : Lat: " + loc.getLatitude() + " Lng: " + loc.getLongitude(), Toast.LENGTH_SHORT).show(); GeoPoint p = new GeoPoint( (int) (loc.getLatitude() * 1E6), (int) (loc.getLongitude() * 1E6)); mc.setCenter(p); mc.setZoom(16); } } @Override public void onProviderDisabled(String provider) { Toast.makeText(getBaseContext(), "onProviderDisabled provider = " + provider, Toast.LENGTH_SHORT).show(); } @Override public void onProviderEnabled(String provider) { Toast.makeText(getBaseContext(), "onProviderEnabled provider = " + provider, Toast.LENGTH_SHORT).show(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Toast.makeText(getBaseContext(), "onStatusChanged provider = " + provider +"status = " + status, Toast.LENGTH_SHORT).show(); } } } |